I am ashamed to even ask this question, but after a tedious google search (starting with MSDN ...), I decided to post it:
Learning how to program on a client server has just begun (using C #) and trying to write my first code using tcpClient. I write both server and client side. here is my question: Constantly the client sends one line to the server, and then the server sends the String back to the client and so on. Can the server send 2 lines in a row? should he wait for the client to respond? is a client server principle
Once again, sorry for the lousy question. Thanks...
<> I will try to publish part of my code (long ...). I tried to cut out the eloquent parts, so I hope the code makes some sense ... (I designated the main problam with // *********)
public class MServer2 { Dictionary<String, String> nameAndPass = new Dictionary<String, String>(); Dictionary<String, List<String> > nameAndMail = new Dictionary<String, List<String>>(); public static void Main() { new MServer2(); } public MServer2() { TcpListener server = new TcpListener(8500); try { server.Start(); Console.WriteLine("started " + server); while (true) { TcpClient client = server.AcceptTcpClient(); Console.WriteLine("connection accepted " + client); new Server1(client, nameAndPass, nameAndMail); } } catch (Exception e) { Console.WriteLine("exception" + e); } finally { server.Stop(); } } class Server1 { TcpClient client; NetworkStream netStream; Dictionary<String, String> nameAndPass1 = new Dictionary<String, String>(); Dictionary<String, List<String>> nameAndMail1 = new Dictionary<String, List<String>>(); internal Server1(TcpClient client, Dictionary<String, String> nameandPassFromFile, Dictionary<String, List<String> > nameAndMailsFromFile) { nameAndPass1 = nameandPassFromFile; nameAndMail1 = nameAndMailsFromFile; this.client = client; Thread thr = new Thread(new ThreadStart(Run)); thr.Start(); } public void Run() { try { netStream = client.GetStream(); StreamReader reader = new StreamReader(netStream); StreamWriter writer = new StreamWriter(netStream); writer.AutoFlush = true; Console.WriteLine("beginning to receive loop"); writer.WriteLine("Choose your user name."); strFromClient = reader.ReadLine(); userName = strFromClient; writer.WriteLine("Choose your user password."); strFromClient = reader.ReadLine(); password = strFromClient; writer.WriteLine("Do you want to see the list of email addresses? (y/n)"); strFromClient = reader.ReadLine();
EDIT VOL 2
OK! After 2 hours of suffering, I think I found problam thanks to Phil Frost (genius!) --- problam, probably in the client ... (Im souch a-hole!).
The server sends 2 lines in a row, but my stupid client-side implementation does not display a message (which is retrieved from the server) that does not follow the message sent by the client ...
So again I need your help. Here is a view of how I created the client form: 
The lack of experience led me to connect to the server when I clicked "connect to server", and only when I clicked "Send message" is a message from the server displayed. The problem is that 2 (or more) messages from the server are returned without sending a message from the client to the server - the client does not know that a new message has been received! Where, in my opinion, can I get messages from the server? ("where" means under which function, for example, right now this is happening in the sendMessage_click function).
Thanks again for the help!