I'm working on a low latency financial application that receives tcp data over sockets.
This is how I'm making a socket connection and receiving bytes:
public class IncomingData
{
Socket _Socket;
byte[] buffer = new byte[4096];
public static void Connect(IPEndPoint endPoint)
{
_Socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
_Socket.Connect(endPoint);
}
public static void ReadSocket(int ReadQty)
{
_Socket.Receive(buffer, 0, ReadQty, SocketFlags.None);
}
}
I heard that when you call Receive()
on a Stream socket, that the calling thread is put to sleep, and it is woken up when data is received. I would like the thread to be running at full speed (using CPU capacity).
Is there a way I can do this using a Stream socket? If the only way is with a Raw socket, could you provide an example?