public void Connect(Action <ReverseAsyncSocket> callback) { _callbackConnect.Add(callback); if (_callbackConnect.Count > 1) { return; } _socket.Connect(socket => { var reverseSocket = new ReverseAsyncSocket(socket); _callbackConnect.ForEach(cb => cb(reverseSocket)); }); }
public void ReverseServerToServer(ReverseAsyncSocket reverseServer, AsyncSocket server) { var id = 0; reverseServer.Connect(reverseSocket => server.Connect(socket => { var tid = id++; reverseSocket.Read((sid, command, buffer) => { if (sid == tid) { socket.Write(buffer); } }); socket.Read((buffer, count) => reverseSocket.Write(tid, Command.Data, buffer, 0, count)); })); }
public void ReverseClientToClient(ReverseAsyncSocket reverseClient, string host, int port) { var clients = new Dictionary <int, AsyncSocket>(); reverseClient.Read((id, command, buffer) => { AsyncSocket client; if (!clients.TryGetValue(id, out client)) { client = new AsyncSocket(); client.Read((cbuffer, ccount) => reverseClient.Write(id, Command.Data, cbuffer, 0, ccount)); client.Connect(host, port); clients[id] = client; client.Connect(socket => client.Write(buffer)); } else { client.Write(buffer); } }); }
public void ListenReverse(int port) { ReverseServer = new ReverseAsyncSocket(); ReverseServerToServer(ReverseServer, Server); ReverseServer.Listen(port); }
public void ConnectReverse(string host, int port) { ReverseClient = new ReverseAsyncSocket(); ReverseClientToClient(ReverseClient, Client.Key, Client.Value); ReverseClient.Connect(host, port); }