public void StartRelay() { try { ClientSocket.BeginReceive(ClientBuffer, 0, ClientBuffer.Length, SocketFlags.None, this.OnClientReceive, ClientSocket); RemoteSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, this.OnRemoteReceive, RemoteSocket); } catch (Exception ex) { Dispose(); Helper.PublishException(ex); } }
// Remote Cycle private void OnClientSent(IAsyncResult ar) { try { if (ClientSocket.Connected) { int length = ClientSocket.EndSend(ar); if (length > 0 && RemoteSocket.Connected) { RemoteSocket.BeginReceive(RemoteBuffer, 0, RemoteBuffer.Length, SocketFlags.None, this.OnRemoteReceive, RemoteSocket); return; } } } catch (Exception ex) { Dispose(); Helper.PublishException(ex); } Dispose(); }