- Home /
TCP Socket waiting for ipnut to continiue reading data
I know the title is not very helpful but i could not write it as a question, sorry. Here is the case:
I have established a TCP connection and everything works great. I use a StreamWriter.WriteLine() to write and StreamReader().ReadLine() in update to read. They both work great. However clients, seem to freeze when reading, until there is input from the user. The input has to do with something that sends a command to the server(not just a random click somewhere). When this is done, client reads the rest of the messages that should have read before with the correct order and then sends the input-command. Note that client reads the first message and seems to pause after that, until the input thing happens. The way i send messages is this:
// Server writing:
writer.WriteLine ("Message 1"); // that message is received without delay
writer.WrtieLine("Message 2"); // this message and the next ones are received after user-input
writer.WrtieLine("Message X");
// Client reading:
void Update () {
if (clientStream.DataAvailable ) {
string data = reader.ReadLine();
if (data != null)
{
OnIncomingData(data); // configures what to do with the message
}
}
}
Also the server is sending all messages as he should with no delay. The problem is with the client.
Thanks in advance
Your answer
![](https://koobas.hobune.stream/wayback/20220612155228im_/https://answers.unity.com/themes/thub/images/avi.jpg)