public void TestServerToClient() { Until((port, done) => { var portTestServer = port; var portServer = portTestServer + 1; var testServer = new AsyncSocket(); var server = new AsyncSocket(); var client = new AsyncSocket(); var netro = new Netro.Netro(); server.Listen(portServer); netro.ServerToClient(server, Host, portTestServer); testServer.Listen(portTestServer, socket => socket.Read(text => { Assert.AreEqual("Hello", text); socket.Write("world!"); })); client.Connect(Host, portServer, () => { client.Read(text => { Assert.AreEqual("world!", text); done(); }); client.Write("Hello"); }); }); }
public static void Main(string[] args) { var netro = new Netro(); var hasListen = false; var hasClient = false; args.ToList().ForEach(arg => { int port; var split = arg.Split(':'); if (split.Length > 1) { port = int.Parse(split[1]); if (!hasClient) { netro.SetClient(split[0], port); } else { netro.ConnectReverse(split[0], port); } hasClient = true; return; } port = int.Parse(arg); if (!hasListen) { netro.Listen(port); } else { netro.ListenReverse(port); } hasListen = true; }); var netroStatus = new NetroStatus(netro); if (netroStatus.CurrentType == NetroStatus.Type.None) { Console.WriteLine("Netro not running, missing arguments?"); Console.WriteLine("Check https://github.com/eirikb/Netro for usage examples"); return; } var output = new Output(netroStatus); Console.Read(); output.Reset(); }
public void FullTest() { Until((port, done) => { var serverPortA = port + 1; var serverPortB = port + 2; var serverA = new AsyncSocket(); var serverB = new AsyncSocket(); var clientA = new AsyncSocket(); var reverseServer = new ReverseAsyncSocket(); var reverseClient = new ReverseAsyncSocket(); var netro = new Netro.Netro(); serverA.Listen(serverPortA); serverB.Listen(serverPortB); reverseServer.Listen(port); netro.ReverseServerToServer(reverseServer, serverA); netro.ReverseClientToClient(reverseClient, Host, serverPortB); reverseServer.Connect(s => { serverB.Connect(socket => socket.Read(text => { Assert.AreEqual("Hello", text); socket.Write("world!"); })); clientA.Connect(Host, serverPortA, () => { clientA.Write("Hello"); clientA.Read(text => { Assert.AreEqual("world!", text); done(); }); }); }); reverseClient.Connect(Host, port, () => { }); }); }
public void TestReverseServerToServer() { Until((port, done) => { var reverseServer = new ReverseAsyncSocket(); var server = new AsyncSocket(); var reverseClient = new ReverseAsyncSocket(); var client = new AsyncSocket(); var netro = new Netro.Netro(); var serverPort = port + 1; reverseServer.Listen(port); server.Listen(serverPort); netro.ReverseServerToServer(reverseServer, server); reverseClient.ReadString((tid, command, text) => { Assert.AreEqual("Hello", text); reverseClient.Write(tid, "world!"); }); client.Read(text => { Assert.AreEqual("world!", text); done(); }); reverseClient.Connect(Host, port, () => { client.Connect(Host, serverPort, () => { client.Write("Hello"); }); }); }); }
public void TestServerToClientDisconnect() { Until((port, done) => { var portTestServer = port; var portServer = portTestServer + 1; var testServer = new AsyncSocket(); var server = new AsyncSocket(); var client = new AsyncSocket(); var netro = new Netro.Netro(); server.Listen(portServer); netro.ServerToClient(server, Host, portTestServer); testServer.Listen(portTestServer, socket => socket.Disconnect()); client.Connect(Host, portServer, () => { client.Read(text => { }); client.Disconnect(done); }); }); }
public void ReverseClientToClient() { Until((port, done) => { var serverPort = port + 1; var reverseServer = new ReverseAsyncSocket(); var server = new AsyncSocket(); var reverseClient = new ReverseAsyncSocket(); var netro = new Netro.Netro(); netro.ReverseClientToClient(reverseClient, Host, serverPort); reverseServer.Listen(port); server.Listen(serverPort); reverseClient.Connect(Host, port, () => { }); server.Connect(socket => socket.Read(text => { Assert.AreEqual("Hello", text); socket.Write("world!"); })); reverseServer.Connect(socket => { socket.ReadString((id, command, text) => { Assert.AreEqual("world!", text); done(); }); socket.Write(42, "Hello"); }); }); }
public NetroStatus(Netro netro) { _netro = netro; }