public void Start() { try { _remote = new Socket(_remoteEP.AddressFamily, SocketType.Dgram, ProtocolType.Udp); _remote.SetSocketOption(SocketOptionLevel.Udp, SocketOptionName.NoDelay, true); _remote.BeginConnect(_remoteEP, new AsyncCallback(remoteConnectCallback), null); Delay(); } catch (Exception e) { _relay.onError(new RelayErrorEventArgs(e)); this.Close(); } }
public void Start(Socket socket) { this._local = socket; try { _remote = new Socket(_remoteEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); _remote.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); // Connect to the remote endpoint. _remote.BeginConnect(_remoteEP, new AsyncCallback(ConnectCallback), null); } catch (Exception e) { _relay.onError(new RelayErrorEventArgs(e)); this.Close(); } }
public void Start(Socket socket) { this._local = socket; try { _remote = new Socket(_remoteEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp); _remote.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true); _id = System.Threading.Interlocked.Increment(ref _maxid); // Connect to the remote endpoint. _relay.onWriteLog(new WriteLogEventArgs($"\r\n{_id}: 连接 {_remoteEP} ...\r\n")); _remoteTime = Environment.TickCount; _remote.BeginConnect(_remoteEP, new AsyncCallback(ConnectCallback), null); } catch (Exception e) { _relay.onError(new RelayErrorEventArgs(e)); this.Close(); } }