There is a single-threaded server using the .NET Socket with TCP and Socket.Pool(), Socket.Select(), Socket.Receive().
To send, I used:
public void SendPacket(int clientid, byte[] packet)
{
clients[clientid].socket.Send(packet);
}
But it was very slow when sending a large amount of data to one client (stopping the entire main thread), so I replaced it with this:
public void SendPacket(int clientid, byte[] packet)
{
using (SocketAsyncEventArgs e = new SocketAsyncEventArgs())
{
e.SetBuffer(packet, 0, packet.Length);
clients[clientid].socket.SendAsync(e);
}
}
It works fine on Windows with .NET (I donβt know if this is great), but on Linux with Mono, packages are either discarded or reordered (I donβt know). Reverting to the slow version using Socket.Send () works on Linux. Source for the entire server .
How to write a non-blocking SendPacket () function that works on Linux?
source
share