private static unsafe IntPtr CreateListeningSocket() { var socketFlags = SocketFlags.WSA_FLAG_REGISTERED_IO | SocketFlags.WSA_FLAG_OVERLAPPED; var listeningSocket = WinSock.WSASocket(AddressFamilies.AF_INET, SocketType.SOCK_STREAM, Protocol.IPPROTO_TCP, IntPtr.Zero, 0, socketFlags); if (listeningSocket == (IntPtr)WinSock.Consts.INVALID_SOCKET) { WinSock.ThrowLastWsaError(); return(IntPtr.Zero); } var tcpNoDelay = -1; WinSock.setsockopt(listeningSocket, WinSock.Consts.IPPROTO_TCP, WinSock.Consts.TCP_NODELAY, (char *)&tcpNoDelay, sizeof(int)); var reuseAddr = 1; WinSock.setsockopt(listeningSocket, WinSock.Consts.SOL_SOCKET, WinSock.Consts.SO_REUSEADDR, (char *)&reuseAddr, sizeof(int)); return(listeningSocket); }