/// <summary> /// 启动所有的Channels,开始监听 /// </summary> public static void Start() { foreach (var channel in _channels) { channel.Start(); _tracing.WarnFmt("RpcChannel<{0}> Started on {1}", channel.Protocol, channel.ServerUrl); } }
private void BeginReceiveCallback(IAsyncResult result) { Socket s = result.AsyncState as Socket; int size; try { if (!s.Connected) { return; } size = s.EndReceive(result); if (size < 1) { // Close(); lock (_syncReceive) { if (_socket != null) { BeginReceive(); } } } else { _lastActiveTime = DateTime.Now; _lastDataReceivedTime = DateTime.Now; _evenArgs.SetSize(size); lock (_syncReceive) { if (DataReceived != null) { DataReceived(this, _evenArgs); } if (_socket != null) { BeginReceive(); } } } } catch (SocketException ex) { Socket sEx = _socket; if (sEx != null) { _tracing.ErrorFmt(ex, "SocketDataTransceiver接收数据发生异常,SocketErrorCode:{0},RemoteEndPoint:{1},SocketDataTransceiver将被迫关闭!", ex.SocketErrorCode, sEx == null ? "null" : ((IPEndPoint)(sEx.RemoteEndPoint)).ToString()); } else { _tracing.WarnFmt(ex, "SocketDataTransceiver接收数据发生异常,SocketErrorCode:{0},SocketDataTransceiver将被迫关闭!", ex.SocketErrorCode); } Close(); } catch (ObjectDisposedException ex) { _tracing.Error(ex, "因为socket已释放,SocketDataTransceiver接收数据发生异常,SocketDataTransceiver将被迫关闭!"); Close(); } catch (Exception ex) { _tracing.Error(ex, "SocketDataTransceiver接收数据发生异常,SocketDataTransceiver将被迫关闭!"); Close(); } }