private void TransportKeepAlive() { if (_transport.IsSocketConnected == false) { try { _transport.Close(); } catch { } } var transportState = _transport.State; if (transportState == -1) { _transport = new TcpTransport(this, ServerIP, ServerPort); _transport.Init(); } if (transportState == 0) { _transport.Init(); } }
private void CheckTransport() { var transportState = _transport.State; if (transportState == TcpTransportState.Closed) { throw new RpcException("SimpleRpcClient CheckTransport failed,connection has been closed"); } if (transportState == TcpTransportState.Uninit) { try { _transport.Init(); } catch (Exception ex) { try { _transport.Close(); } catch { } LogAgent.Warn("close network in SimpleRpcClient CheckTransport,transport init error", ex); throw; } } }
private void CheckConnection() { if (_transport.State == -1 || _transport.IsSocketConnected == false) { try { _transport.Close(); } catch { } _transport = new TcpTransport(this, ServerIP, ServerPort); _transport.Init(); } if (_transport.State == 0) { _transport.Init(); } }
private void AcceptSocketCallback(IAsyncResult ar) { if (_serverState != 2) { return; } var server = (Socket)ar.AsyncState; Socket client = null; IPEndPoint ipEndPoint = null; try { client = server.EndAccept(ar); ipEndPoint = (IPEndPoint)client.RemoteEndPoint; } catch (Exception ex) { LogAgent.Warn("RpcServer AcceptSocketCallback failed,EndAccept error", ex); } try { server.BeginAccept(AcceptSocketCallback, server); } catch (Exception ex) { Close(); try { if (client != null) { client.Close(); } } catch { } LogAgent.Warn("close network in RpcServer AcceptSocketCallback,BeginAccept error", ex); return; } if (ipEndPoint == null) { try { if (client != null) { client.Close(); } } catch { } LogAgent.Warn("close network in RpcServer AcceptSocketCallback,client RemoteEndPoint is null"); return; } var tcpTransport = new TcpTransport(this, ipEndPoint.Address, ipEndPoint.Port); try { tcpTransport.Init(client); } catch (Exception ex) { try { tcpTransport.Close(); } catch { } LogAgent.Warn("close network in RpcServer AcceptSocketCallback,tcpTransport Init error", ex); return; } _clientTransportDictionary[tcpTransport.Key] = tcpTransport; }
private void AcceptSocketCallback(IAsyncResult ar) { if (_serverState != 1) { return; } var server = (TcpListener)ar.AsyncState; Socket client = null; IPEndPoint ipEndPoint = null; try { client = server.EndAcceptSocket(ar); ipEndPoint = (IPEndPoint)client.RemoteEndPoint; } catch { } try { server.BeginAcceptSocket(AcceptSocketCallback, server); } catch { Close(); return; } if (client == null) { return; } if (ipEndPoint == null) { try { client.Close(); } catch { } return; } var tcpTransport = new TcpTransport(this, ipEndPoint.Address, ipEndPoint.Port); try { tcpTransport.Init(client); } catch { try { tcpTransport.Close(); } catch { } return; } }
private void AcceptSocketCallback(IAsyncResult ar) { if (_serverState != 1) { return; } var server = (Socket)ar.AsyncState; Socket client = null; IPEndPoint ipEndPoint = null; try { client = server.EndAccept(ar); ipEndPoint = (IPEndPoint)client.RemoteEndPoint; } catch (Exception ex) { LogAgent.Error(ex.Message); } try { server.BeginAccept(AcceptSocketCallback, server); } catch (Exception ex) { Close(); try { if (client != null) { client.Close(); } } catch { } LogAgent.Error(ex.Message); return; } if (ipEndPoint == null) { try { if (client != null) { client.Close(); } } catch { } return; } var tcpTransport = new TcpTransport(this, ipEndPoint.Address, ipEndPoint.Port); try { tcpTransport.Init(client); } catch (Exception ex) { try { tcpTransport.Close(); } catch { } LogAgent.Error(ex.Message); return; } _clientTransportDictionary[tcpTransport.Key] = tcpTransport; }