I am writing a server/client application and I have encountered a weird problem. The server handles several TCP connections and sometimes sends messages to the clients. Now, if I send these messages too "fast" they are not sent at all. However, if a Thread.Sleep(1000); command is introduced before sending a message everything works fine (except it is very slow). Maybe it is relevant that the Send() method is called by different threads , triggered by events (locking the communication object does not help). Here is the code:
public void Send(int id, string message)
{
//Thread.Sleep(1000);
StreamWriter writer = new StreamWriter(connections_[id].GetStream());
// type of connections_ is Dictionary<int, TcpClient>
writer.WriteLine(message);
writer.Flush();
}

New Topic/Question
Reply




MultiQuote




|