Socket+StreamWriter

  • Thread starter Thread starter Vladimir Bezugliy
  • Start date Start date
V

Vladimir Bezugliy

I have a server that listen a socket.

And I have next client:

TcpClient socketForServer = new TcpClient("IVBEZUGLIY", 21000);
NetworkStream networkStream = socketForServer.GetStream();
StreamWriter streamWriter = new StreamWriter(networkStream);
streamWriter.Write("Hello12345!!!");
streamWriter.Flush();
//streamWriter.Close();

socketForServer = new TcpClient("IVBEZUGLIY", 21000);
networkStream = socketForServer.GetStream();
streamWriter = new StreamWriter(networkStream);
streamWriter.Write("Bye-bye!!!");
streamWriter.Flush();
//streamWriter.Close();


But server get only first message.
If I remove comments, then server get both messages.
Is it a bug? Or I do not know something?
 
Vladimir Bezugliy said:
I have a server that listen a socket.

And I have next client:

TcpClient socketForServer = new TcpClient("IVBEZUGLIY", 21000);
NetworkStream networkStream = socketForServer.GetStream();
StreamWriter streamWriter = new StreamWriter(networkStream);
streamWriter.Write("Hello12345!!!");
streamWriter.Flush();
//streamWriter.Close();

socketForServer = new TcpClient("IVBEZUGLIY", 21000);
networkStream = socketForServer.GetStream();
streamWriter = new StreamWriter(networkStream);
streamWriter.Write("Bye-bye!!!");
streamWriter.Flush();
//streamWriter.Close();


But server get only first message.
If I remove comments, then server get both messages.
Is it a bug? Or I do not know something?

When you close the StreamWriter, that's also closing the connection.
Does your server listen for multiple connections, or does it only pick
up the first connection to come in?
 
Back
Top