请教高手:SocketAsyncEventArgs 类服务端如何设置心跳超时
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了请教高手:SocketAsyncEventArgs 类服务端如何设置心跳超时相关的知识,希望对你有一定的参考价值。
private void ProcessAccept(SocketAsyncEventArgs e)
Interlocked.Increment(ref m_numConnectedSockets);
Console.WriteLine("Client connection accepted. There are 0 clients connected to the server",
m_numConnectedSockets);
e.AcceptSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 3000);
// Get the socket for the accepted client connection and put it into the
//ReadEventArg object user token
SocketAsyncEventArgs readEventArgs = m_readWritePool.Pop();
((AsyncUserToken)readEventArgs.UserToken).Socket = e.AcceptSocket;
// As soon as the client is connected, post a receive to the connection
bool willRaiseEvent = e.AcceptSocket.ReceiveAsync(readEventArgs);
if (!willRaiseEvent)
ProcessReceive(readEventArgs);
// Accept the next connection request
StartAccept(e);
通过: e.AcceptSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 3000); 设置3秒无效。
以上是关于请教高手:SocketAsyncEventArgs 类服务端如何设置心跳超时的主要内容,如果未能解决你的问题,请参考以下文章