Hi
I am currently working on a project that involves a server and multiple clients that can connect to it and request data. Im sending messages (strings) from the client to the server and vice versa (never between clients), but sometimes they dont get sent but are stuck until I try to send it again, and then both messages are sent at the same time. At first this seemed easy to solve: the packets are automatically stored until there is enough data to send out in order to save bandwith (aka Nagle algorithm), so setting tcpclient.NoDelay = true should do the trick, but it didnt. I've tried to solve this for days now, but can't get any progress on it.
Im using a BinaryWriter for sending data, and also tried the tcpclient.Client.Send(byte[]) method with the same results.
public Client()
{
this.tcpClient = new TcpClient();
this.tcpClient.NoDelay = true;
this.outgoingMessages = new List<string>();
}
/// <summary>
/// Write pending messages to the server.
/// </summary>
private void Write() //This is running in a thread
{
while (true)
{
lock (this.outgoingMessages)
{
if (this.binaryWriter != null && this.outgoingMessages.Count > 0)
{
this.binaryWriter.Write(this.outgoingMessages[0]);
this.binaryWriter.Flush();
this.outgoingMessages.RemoveAt(0);
}
}
Thread.Sleep(33);
}
}
Hopefully someone knows an answer to this