Search code examples
c#socketstcpwinsock2

Can you setup recive call in System.Net.Sockets to behave as winsocket2 WSARecv with MSG_PUSH_IMMEDIATE flag set


I am connecting to server that doesn't set PSH flag on its TCP packets. As latency is important I need to ignore PSH flag on receive and forward whatever is in the buffer immediately.

This is possible in winsock2 api with WSARecv function and MSG_PUSH_IMMEDIATE flag. Is same functionality possible with .net socket?


Solution

  • Looks like Rowan Smith idea works. I added (SocketFlags)0x20 to BeginReceive() function and it got propagated to the WSARecv() function in the background so latency was removed.

    I checked .net framework 4.5.1 and 4.8 and both implementations just pass SocketFlags to WSARecv() without using or modifying them.

    Thanks!