public void Process(IStreamServer server) { new StreamPump(server.Streams[StreamIndex], data => server.WriteMessage(new StreamData(StreamIndex, data)), ex => { server.Log("Forwarded port closed: " + RemoteEndPoint + " to " + LocalEndPoint); server.WriteMessage(new StreamError(StreamIndex, ex)); }).Pump(); }
public void Process(IStreamServer server) { try { server.Listeners[StreamIndex] = TcpListenerHelper.Start(Address, Port, client => { var streamIndex = --server.ConnectionCount; server.Streams[streamIndex] = client.GetStream(); server.WriteMessage(new AcceptRequest(StreamIndex, streamIndex, client.Client.RemoteEndPoint.ToString())); }, exception => server.WriteMessage(new StreamError(StreamIndex, new EndOfStreamException()))); server.WriteMessage(new ListenResponse(StreamIndex)); } catch (Exception ex) { server.WriteMessage(new StreamError(StreamIndex, ex)); } }
public void Process(IStreamServer server) { var client = new TcpClient(); client.BeginConnect(Address, Port, ar => { try { client.EndConnect(ar); server.Streams[StreamIndex] = client.GetStream(); var connectResult = new ConnectResponse(StreamIndex, LocalEndPoint, client.Client.RemoteEndPoint.ToString()); connectResult.Process(server); server.WriteMessage(connectResult); } catch (Exception ex) { Debug.Print(DateTime.Now + " " + Environment.MachineName + ": " + ex); server.WriteMessage(new StreamError(StreamIndex, ex)); } }, null); }
public void Process(IStreamServer server) { Stream stream; lock (server.Streams) { if (!server.Streams.ContainsKey(StreamIndex)) { return; } stream = server.Streams[StreamIndex]; } try { stream.Write(Data, 0, Data.Length); } catch (Exception ex) { server.WriteMessage(new StreamError(StreamIndex, ex)); } }
public void Process(IStreamServer server) { server.WriteMessage(new HelloResponse()); }