void Server()
{
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
server.Bind(ServerEndPoint);
server.Listen(1);
Socket s = server.Accept();
while (true)
{
// measure how long it takes to receive both messages
Stopwatch stopwatch = Stopwatch.StartNew();
s.Receive(new byte[8]);
s.Receive(new byte[8]);
// Output: around 200ms
Console.WriteLine(stopwatch.ElapsedMilliseconds);
}
}
void Client()
{
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
client.Bind(ClientEndPoint);
client.Connect(ServerEndPoint);
while (true)
{
client.Send(new byte[8]); // will be sent immediately
client.Send(new byte[8]); // delayed for 200ms
// wait for an imaginery response
client.Receive(new byte[0]);
}
}