public void Initialize() { server = new EchoServer(20015); t = new Thread(new ThreadStart(server.init)); t.Name = "Listener"; t.Start(); }
public void EchoMessage() { int port = 41717; using (var server = new EchoServer()) { server.Start(port); using (var client = new EchoClient()) { var sendMessage = "abc"; string receiveMessage = null; client.Connect(IPAddress.Loopback, port); client.PacketReceived += reader => { reader.Reset(); reader.Read <ushort>(); receiveMessage = reader.ReadString(); }; ClientToServer.Rpc.RequestEcho(client, sendMessage); client.FlushPackets(); Waiting.Until(() => receiveMessage != null); receiveMessage.Should().Be(sendMessage); } } }
public void MultipleClientsSingleThread2() { EchoServer echoServer = new EchoServer(); echoServer.Start(new IPEndPoint(IPAddress.Any, 2033)); List <IPEndPoint> endPoints = new List <IPEndPoint>(); IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2033); endPoints.Add(ep); List <EchoTestClient> aClients = new List <EchoTestClient>(); for (int i = 0; i < 10; i++) { EchoTestClient echoClient = new EchoTestClient(endPoints); echoClient.Connect(endPoints[0]); aClients.Add(echoClient); } string strTestData2 = "JjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890AaBbCcDdEeFfGgHhJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890AaBbCcDdEeFfGgHh"; for (int j = 0; j < 10; j++) { EchoTestClient clientMaster = aClients[j]; clientMaster.SendData(strTestData2); for (int i = 0; i < 10; i++) { EchoTestClient echoClient = aClients[i]; echoClient.DataReady.WaitOne(); Assert.IsTrue(string.Equals(strTestData2, echoClient.ReceivedData)); } } }
public static void BandwidthThrottlingProxyEcho() { using (var echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0))) { echoServer.Start(); var listener = new ThrottlingListener( SinkListener.Instance, 10 * 1024 /* 10 Kb/s */ ); var connector = new SimpleConnector(echoServer.EndPoint, listener); using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector)) { proxyServer.Start(); var block = Encoding.UTF8.GetBytes(new string('?', 1024)); var stopwatch = Stopwatch.StartNew(); using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block)) { echoClient.Start(); for (int i = 0; i < 100; i++) { echoClient.Ping(); } } Console.WriteLine(stopwatch.Elapsed); } } }
public void Echoサーバに送信して溜まったデータサイズ_lengthを確認する() { //setUp const string addr = "127.0.0.1"; const int port = 9982; var sv = new EchoServer(addr, port); sv.Start(); var sut = new SockTcp(new Kernel(), new Ip(addr), port, 100, null); const int max = 1000; for (int i = 0; i < 3; i++) { sut.Send(new byte[max]); } Thread.Sleep(200); int expected = max * 3; //exercise var actual = sut.Length(); //verify Assert.That(actual, Is.EqualTo(expected)); //tearDown sut.Close(); sv.Stop(); }
public static void DelayTransferEchoServer() { using (var echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0))) { echoServer.Start(); var listener = new FixedDelayListener( SinkListener.Instance, TimeSpan.FromSeconds(0.5) ); var connector = new SimpleConnector(echoServer.EndPoint, listener); using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector)) { proxyServer.Start(); var block = Encoding.UTF8.GetBytes("Hello world!"); using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block)) { echoClient.Start(); var stopwatch = Stopwatch.StartNew(); echoClient.Ping(); Console.WriteLine(stopwatch.Elapsed); } } } }
public void EchoサーバにstringSendで1行送信してstringRecvで1行受信する() { //setUp const string addr = "127.0.0.1"; const int port = 9993; var sv = new EchoServer(addr, port); sv.Start(); var sut = new SockTcp(new Kernel(), new Ip(addr), port, 100, null); sut.StringSend("本日は晴天なり", "UTF-8"); Thread.Sleep(10); var expected = "本日は晴天なり\r\n"; //exercise var actual = sut.StringRecv("UTF-8", 1, this); //verify Assert.That(actual, Is.EqualTo(expected)); //tearDown sut.Close(); sv.Stop(); }
public void EchoサーバにlineSendで1行送信してlineRecvで1行受信する() { //setUp const string addr = "127.0.0.1"; const int port = 9993; var sv = new EchoServer(addr, port); sv.Start(); var sut = new SockTcp(new Kernel(), new Ip(addr), port, 100, null); sut.LineSend(Encoding.UTF8.GetBytes("本日は晴天なり")); Thread.Sleep(10); var expected = "本日は晴天なり\r\n"; //exercise var bytes = sut.LineRecv(1, this); var actual = Encoding.UTF8.GetString(bytes); //verify Assert.That(actual, Is.EqualTo(expected)); //tearDown sut.Close(); sv.Stop(); }
private void ActivateServers() { AddLog("Trying to activate servers..."); fEchoServer = new EchoServer(); try { fEchoServer.Open(); AddLog("EchoServer is active."); } catch (Exception ex) { AddLog("Can't activate EchoServer. An exception occured: " + ex.Message); } fHttpServer = new SimpleHttpServer(); fHttpServer.Port = Convert.ToInt32(nudPort.Value); fHttpServer.RootPath = txtRoot.Text; fHttpServer.ServerName = txtServerName.Text; if (this.fHttpServer.BindingV4 != null) { this.fHttpServer.BindingV4.ListenerThreadCount = Convert.ToInt32(this.nudCount.Value); } fHttpServer.HttpRequest += OnHttpRequest; fHttpServer.Open(); AddLog(String.Format("SimpleHttpServer is active on {0} port.", fHttpServer.Port)); SetEnable(false); AddLog("Servers activated."); btnAction.Text = "Deactivate Servers"; }
/// ----------------------------------------------------------------------------- /// <summary> /// Initialise les différents serveurs pour le test /// </summary> /// <typeparam name="T">le protocole à utiliser</typeparam> /// <param name="port">le port de base pour le remoting</param> /// <param name="server">le serveur (tunnel)</param> /// <param name="client">le client (tunnel)</param> /// <param name="echo">le serveur d'echo</param> /// <param name="gw">la passerelle</param> /// ----------------------------------------------------------------------------- private void Initialize <T>(int port, out BdtServer server, out BdtClient client, out EchoServer echo, out GatewayServer gw) where T : GenericProtocol { Assert.AreEqual(ChannelServices.RegisteredChannels.Length, 0); var config = new TestConfigPackage(typeof(T).FullName, port); server = new TestServer(TestContext, config); client = new TestClient(TestContext, config); var args = new String[] { }; server.LoadConfiguration(args); client.LoadConfiguration(args); Tunnel.Configuration = server.Configuration; Tunnel.Logger = LoggedObject.GlobalLogger; server.Protocol.ConfigureServer(typeof(Tunnel)); client.StartClient(); Assert.AreEqual(ChannelServices.RegisteredChannels.Length, 2); echo = new EchoServer(port + EchoOffset, false); Servers.Add(echo); gw = new GatewayServer(port + GatewayOffset, false, port + EchoOffset, "localhost", client.Tunnel, client.Sid); Servers.Add(gw); }
public static void Main(String[] args) { TcpListener server=null; try { //Echo servers listen on port 7 int portNumber = 7; //Echo server first binds to port 7 server = new TcpListener(portNumber); //Server starts listening server.Start(); //Echo server loops forever, listening for clients for(;;) { //Accept the pending client connection and return a client //initialized for communication //This method will block until a connection is made EchoServer es = new EchoServer(server.AcceptTcpClient()); //Allow this conversation to run in a new thread Thread serverThread = new Thread( new ThreadStart(es.Conversation)); serverThread.Start(); //Loop back up and wait for another client //Another thread is servicing this client } } catch (Exception e) { Console.WriteLine(e+" "+e.StackTrace); } finally { //Release the port and stop the server server.Stop(); } }
public void Echoサーバにsendしてlength分ずつRecvする() { //setUp const string addr = "127.0.0.1"; const int port = 53; var echoServer = new EchoServer(addr, port); echoServer.Start(); const int timeout = 3; const int max = 1500; const int loop = 10; var tmp = new byte[max]; for (int i = 0; i < max; i++){ tmp[i] = (byte) i; } var ip = new Ip(addr); for (var i = 0; i < loop; i++){ var sockUdp = new SockUdp(new Kernel(), ip, port, null, tmp); // while (sockUdp.Length() == 0){ // Thread.Sleep(10); // } var b = sockUdp.Recv(timeout); //verify for (var m = 0; m < max; m += 10){ Assert.That(b[m], Is.EqualTo(tmp[m])); //送信したデータと受信したデータが同一かどうかのテスト } sockUdp.Close(); } //TearDown echoServer.Stop(); }
public void OneServerを継承したEchoServer_TCP版_を使用して接続する() { const string addr = "127.0.0.1"; const int port = 9999; const int timeout = 300; Ip ip = null; try{ ip = new Ip(addr); } catch (ValidObjException ex) { Assert.Fail(ex.Message); } var oneBind = new OneBind(ip, ProtocolKind.Tcp); var conf = TestUtil.CreateConf("OptionSample"); conf.Set("port", port); conf.Set("multiple", 10); conf.Set("acl", new Dat(new CtrlType[0])); conf.Set("enableAcl", 1); conf.Set("timeOut", timeout); var echoServer = new EchoServer(conf, oneBind); echoServer.Start(); //TCPクライアント const int max = 10000; var buf = new byte[max]; buf[8] = 100; //CheckData for (int i = 0; i < 3; i++) { var sockTcp = new SockTcp(new Kernel(), ip, port, timeout, null); sockTcp.Send(buf); while (sockTcp.Length() == 0) { Thread.Sleep(2); } var len = sockTcp.Length(); if (0 < len) { var b = sockTcp.Recv(len, timeout, this); Assert.That(b[8], Is.EqualTo(buf[8]));//CheckData } Assert.That(max, Is.EqualTo(len)); sockTcp.Close(); } echoServer.Dispose(); }
static void Main() { var server = new EchoServer(); new Thread(server.Start).Start(); var client = new Client { Message = "hello world" }; new Thread(client.Start).Start(); var client2 = new Client { Message = "foo bar" }; new Thread(client2.Start).Start(); }
public void Initialize() { Debug.WriteLine("Init"); server = new EchoServer(20015); t = new Thread(new ThreadStart(server.init)); t.Name = "Listener"; t.Start(); Debug.WriteLine("Listening"); c = new CanalSocket("localhost", 20015); Debug.WriteLine("Canal criado"); m = new Medidor(c); Debug.WriteLine("Medidor criado"); m.connect(); }
public void Echoサーバにsendで送信てtcpQueueのlength分ずつRecvする() { const string addr = "127.0.0.1"; const int port = 9981; var echoServer = new EchoServer(addr, port); echoServer.Start(); const int timeout = 100; Ip ip = null; try{ ip = new Ip(addr); } catch (ValidObjException ex) { Assert.Fail(ex.Message); } var sockTcp = new SockTcp(new Kernel(), ip, port, timeout, null); const int max = 1000; const int loop = 3; var tmp = new byte[max]; for (var i = 0; i < max; i++) { tmp[i] = (byte)i; } int recvCount = 0; for (var i = 0; i < loop; i++) { var len = sockTcp.Send(tmp); Assert.That(len, Is.EqualTo(tmp.Length)); Thread.Sleep(10); var b = sockTcp.Recv(len, timeout, this); recvCount += b.Length; for (int m = 0; m < max; m += 10) { Assert.That(b[m], Is.EqualTo(tmp[m])); //送信したデータと受信したデータが同一かどうかのテスト } } Assert.That(loop * max, Is.EqualTo(recvCount)); //送信したデータ数と受信したデータ数が一致するかどうかのテスト sockTcp.Close(); echoServer.Stop(); }
public void OneServerを継承したEchoServer_TCP版_を使用して接続する() { const string addr = "127.0.0.1"; const int port = 9999; const int timeout = 300; Ip ip = null; try{ ip = new Ip(addr); } catch (ValidObjException ex){ Assert.Fail(ex.Message); } var oneBind = new OneBind(ip, ProtocolKind.Tcp); var conf = TestUtil.CreateConf("OptionSample"); conf.Set("port", port); conf.Set("multiple", 10); conf.Set("acl", new Dat(new CtrlType[0])); conf.Set("enableAcl", 1); conf.Set("timeOut", timeout); var echoServer = new EchoServer(conf, oneBind); echoServer.Start(); //TCPクライアント const int max = 10000; var buf = new byte[max]; buf[8] = 100; //CheckData for (int i = 0; i < 3; i++){ var sockTcp = new SockTcp(new Kernel(), ip, port, timeout, null); sockTcp.Send(buf); while (sockTcp.Length() == 0){ Thread.Sleep(2); } var len = sockTcp.Length(); if (0 < len){ var b = sockTcp.Recv(len, timeout, this); Assert.That(b[8], Is.EqualTo(buf[8]));//CheckData } Assert.That(max, Is.EqualTo(len)); sockTcp.Close(); } echoServer.Dispose(); }
static void Main(string[] args) { Trace.Listeners.Add(new ConsoleTraceListener()); // 加载服务器 using (EchoServer server = new EchoServer()) { server.Port = 8088; server.Start(); Console.WriteLine("Press enter key to exit..."); Console.ReadLine(); server.Stop(); } }
EchoServer StartServer(int port, int enableAcl, Dat acl) { var ip = TestUtil.CreateIp("127.0.0.1"); const int timeout = 300; var oneBind = new OneBind(ip, ProtocolKind.Tcp); var conf = TestUtil.CreateConf("OptionSample"); conf.Set("port", port); conf.Set("multiple", 10); conf.Set("acl", acl); conf.Set("enableAcl", enableAcl); conf.Set("timeOut", timeout); var sv = new EchoServer(conf, oneBind); sv.Start(); return(sv); }
static void Main(string[] args) { //Enable or disable log: EchoConnection.LogReceive = true; //Start the Queues: EchoServer.ServerQueue.Start(); EchoConnection.ClientQueue.Start(); //Address: IPEndPoint address = new IPEndPoint(IPAddress.Loopback, 5588); //Start listening EchoServer server = new EchoServer(); server.Bind(address); //Start 10 accept operations: for (int i = 0; i < 10; i++) { server.Accept(); } //Start client when S is hit. Console.WriteLine("HIT S to start client!"); while (Console.ReadKey(true).Key != ConsoleKey.S) { continue; } //Connect 1000 connections: for (int i = 0; i < 1000; i++) { EchoConnection connection = new EchoConnection(); connection.Connect(address); } //Close app when Q is hit Console.WriteLine("HIT Q to close app."); while (Console.ReadKey(true).Key != ConsoleKey.Q) { continue; } }
static void Main(string[] args) { Logger.AddLogger(new ConsoleLogger()); Logger.AddLogger(new FileLogger($"{DateTime.Now:yyyyMMdd}_EchoServerLog.txt")); Logger.EnableAutoFlush(); if (Arguments.TryParse(args, out var arguments) == false) { Logger.LogError("Invalid arguments.\nUsage: Neti.EchoServer {Port}"); Environment.Exit(1); return; } using (var echoServer = new EchoServer()) { echoServer.Started += () => Logger.LogInfo("# Server Started."); echoServer.Stopped += () => Logger.LogInfo("# Server Stopped."); echoServer.SessionEntered += session => { var clientId = $"{session.RemoteAddress}:{session.RemotePort}"; Logger.LogInfo($"# Client Entered. ({clientId})"); session.Disconnected += () => Logger.LogInfo($"# Client Disconnected. ({clientId})"); }; Logger.LogInfo($"# Starting server... (Port: {arguments.Port})"); echoServer.Start(arguments.Port); if (echoServer.IsActive == false) { Logger.LogError("# Failed to start server."); Environment.Exit(2); return; } while (echoServer.IsActive) { Thread.Sleep(17); } } Environment.ExitCode = 0; }
public void Echoサーバにsendで送信てtcpQueueのlength分ずつRecvする() { const string addr = "127.0.0.1"; const int port = 9981; var echoServer = new EchoServer(addr, port); echoServer.Start(); const int timeout = 100; Ip ip = null; try{ ip = new Ip(addr); } catch (ValidObjException ex){ Assert.Fail(ex.Message); } var sockTcp = new SockTcp(new Kernel(), ip, port, timeout, null); const int max = 1000; const int loop = 3; var tmp = new byte[max]; for (var i = 0; i < max; i++){ tmp[i] = (byte) i; } int recvCount = 0; for (var i = 0; i < loop; i++){ var len = sockTcp.Send(tmp); Assert.That(len, Is.EqualTo(tmp.Length)); Thread.Sleep(10); var b = sockTcp.Recv(len, timeout, this); recvCount += b.Length; for (int m = 0; m < max; m += 10){ Assert.That(b[m], Is.EqualTo(tmp[m])); //送信したデータと受信したデータが同一かどうかのテスト } } Assert.That(loop*max, Is.EqualTo(recvCount)); //送信したデータ数と受信したデータ数が一致するかどうかのテスト sockTcp.Close(); echoServer.Stop(); }
static void Main() { Console.WriteLine("-- EchoServer/HelloClient --"); EchoServer.StartEchoServer(); HelloClient.Connect(); Task.Delay(50).Wait(); //Wait 50 milliseconds to let HelloClient finish Console.WriteLine("-- BasicServer/BasicClient --"); BasicServer.StartBasicServer(); BasicClient.Connect(); Task.Delay(50).Wait(); //Wait 50 milliseconds to let BasicClient finish Console.WriteLine("-- EasyTcpPacketExample --"); EasyTcpPacketExample.Start(); EasyTcpPacketExample.Connect(); Task.Delay(50).Wait(); //Wait 50 milliseconds to let EasyTcpPacketExample finish Console.WriteLine("-- EncryptionExample --"); EncryptionExample.Start(); EncryptionExample.Connect(); Task.Delay(50).Wait(); //Wait 50 milliseconds to let EncryptionExample finish Console.WriteLine("-- FileServer/FileClient --"); FileServer.StartFileServer(); FileClient.Download("TestFile.txt", "DownloadedTestFile.txt"); FileClient.Upload("TestFile.txt", "UploadedTestFile.txt"); Task.Delay(50).Wait(); //Wait 50 milliseconds to let FileClient finish Console.WriteLine("-- EchoServer/SpeedTestClient --"); SpeedTestClient.RunSpeedTest(); Console.WriteLine("-- ActionEchoServer/ActionSpeedTestClient --"); ActionEchoServer.StartEchoServer(); ActionSpeedTestClient.RunSpeedTest(); Task.Delay(-1).Wait(); }
public void Setup() { echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0)); echoServer.Start(); if (ContinueMode == ContinueMode.Scheduled) { queue = new BlockingCollection <OperationContinuation>(); thread = new Thread(() => { foreach (var continuation in queue.GetConsumingEnumerable()) { continuation.SetOutcome(OperationOutcome.Continue); } }); thread.Start(); } IListener listener = null; switch (ContinueMode) { case ContinueMode.Continuation: listener = new CompletedContinuationListener(); break; case ContinueMode.Scheduled: listener = new ScheduledContinuationListener(queue); break; } proxy = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), new SimpleConnector(echoServer.EndPoint, listener)); proxy.Start(); var buffer = new byte[BlockSize]; new Random().NextBytes(buffer); echoClient = new EchoPingClient(proxy.EndPoint, buffer); echoClient.Start(); }
public void Echoサーバにsendしてlength分ずつRecvする() { //setUp const string addr = "127.0.0.1"; const int port = 53; var echoServer = new EchoServer(addr, port); echoServer.Start(); const int timeout = 3; const int max = 1500; const int loop = 10; var tmp = new byte[max]; for (int i = 0; i < max; i++) { tmp[i] = (byte)i; } var ip = new Ip(addr); for (var i = 0; i < loop; i++) { var sockUdp = new SockUdp(new Kernel(), ip, port, null, tmp); // while (sockUdp.Length() == 0){ // Thread.Sleep(10); // } var b = sockUdp.Recv(timeout); //verify for (var m = 0; m < max; m += 10) { Assert.That(b[m], Is.EqualTo(tmp[m])); //送信したデータと受信したデータが同一かどうかのテスト } sockUdp.Close(); } //TearDown echoServer.Stop(); }
private static void SimulateNetworkFailureEchoServer() { using (var echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0))) { echoServer.Start(); var configuration = new ChaosConfiguration { Reject = { Percentage = 0.5 } }; var connector = new ChaosConnector( configuration, new SimpleConnector(echoServer.EndPoint) ); using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector)) { proxyServer.Start(); var block = Encoding.UTF8.GetBytes("Hello world!"); int errors = 0; for (int i = 0; i < 100; i++) { using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block)) { echoClient.ExceptionOccured += (s, e) => Interlocked.Increment(ref errors); echoClient.Start(); echoClient.Ping(); } } Console.WriteLine(errors); } } }
/// ----------------------------------------------------------------------------- /// <summary> /// Destruction des entités de test /// </summary> /// <param name="server">le serveur (tunnel)</param> /// <param name="client">le client (tunnel)</param> /// <param name="echo">le serveur d'echo</param> /// <param name="gw">la passerelle</param> /// ----------------------------------------------------------------------------- private void Finalize(ref BdtServer server, ref BdtClient client, ref EchoServer echo, ref GatewayServer gw) { Assert.AreEqual(ChannelServices.RegisteredChannels.Length, 2); client.StopClient(); Tunnel.DisableChecking(); server.Protocol.UnConfigureServer(); server.UnLoadConfiguration(); client.UnLoadConfiguration(); server = null; client = null; Assert.AreEqual(ChannelServices.RegisteredChannels.Length, 0); echo.CloseServer(); Servers.Remove(echo); echo = null; gw.CloseServer(); Servers.Remove(gw); gw = null; }
public static void ProxyEcho() { using (var echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0))) { echoServer.Start(); var connector = new SimpleConnector(echoServer.EndPoint); using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector)) { proxyServer.Start(); var block = Encoding.UTF8.GetBytes("Hello world!"); using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block)) { echoClient.Start(); echoClient.Ping(); } } } }
public static void LoadBalancedProxyEcho() { using (var echoServer1 = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0))) using (var echoServer2 = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0))) using (var echoServer3 = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0))) using (var echoServer4 = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0))) { echoServer1.Start(); echoServer2.Start(); echoServer3.Start(); echoServer4.Start(); var connector = new RoundRobinLoadBalancingConnector( echoServer1.EndPoint, echoServer2.EndPoint, echoServer3.EndPoint, echoServer4.EndPoint ); using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector)) { proxyServer.Start(); var block = Encoding.UTF8.GetBytes("Hello world!"); for (int i = 0; i < 32; i++) { using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block)) { echoClient.Start(); echoClient.Ping(); } } } } }
public static void Main(String[] args) { TcpListener server = null; try { int portNumber = 7; server = new TcpListener(portNumber); server.Start(); //loops listening for clients for (;;) { //gets the clients, will wait here listening for clients EchoServer es = new EchoServer(server.AcceptTcpClient()); //stores the es to keep track of all the clients instances Tuple<EchoServer, string> new_es = new Tuple<EchoServer, string>(es, ""); esnamelist.Add(new_es); //creates threads Thread serverThread = new Thread(new ThreadStart(es.Messaging)); serverThread.Start(); } } catch (Exception e) { Console.WriteLine(e + " " + e.StackTrace); } finally { server.Stop(); } }
public void SingleThreadSingleClient() { EchoServer echoServer = new EchoServer(); echoServer.Start(new IPEndPoint(IPAddress.Any, 2031)); List <IPEndPoint> endPoints = new List <IPEndPoint>(); IPEndPoint ep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2031); endPoints.Add(ep); EchoTestClient echoClient = new EchoTestClient(endPoints); echoClient.Connect(endPoints[0]); string strTestData = "1234567890AaBbCcDdEeFfGgHhJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"; echoClient.SendData(strTestData); echoClient.DataReady.WaitOne(); Assert.IsTrue(string.Equals(strTestData, echoClient.ReceivedData)); string strTestData2 = "JjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890AaBbCcDdEeFfGgHhJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890AaBbCcDdEeFfGgHh"; echoClient.SendData(strTestData2); echoClient.DataReady.WaitOne(); Assert.IsTrue(string.Equals(strTestData2, echoClient.ReceivedData)); }
public void Echoサーバに送信して溜まったデータサイズ_lengthを確認する() { //setUp const string addr = "127.0.0.1"; const int port = 9982; var sv = new EchoServer(addr, port); sv.Start(); var sut = new SockTcp(new Kernel(), new Ip(addr), port, 100, null); const int max = 1000; for (int i = 0; i < 3; i++){ sut.Send(new byte[max]); } Thread.Sleep(200); int expected = max*3; //exercise var actual = sut.Length(); //verify Assert.That(actual, Is.EqualTo(expected)); //tearDown sut.Close(); sv.Stop(); }
static async Task Main() { using var server = new EchoServer(Port); await Task.Yield(); SocketConnection.AssertDependencies(); Log("Connecting..."); using var connection = await SocketConnection.ConnectAsync(new IPEndPoint (IPAddress.Loopback, Port)); Log("Connected"); Guid guid = Guid.NewGuid(); Log($"Writing '{guid}'..."); var output = connection.Output; var memory = output.GetMemory(30); if (!Utf8Formatter.TryFormat(guid, memory.Span, out var bytes)) { throw new FormatException(); } output.Advance(bytes); //Log($"Flushing..."); //var flushResult = await output.FlushAsync(); //Log($"IsCompleted:{flushResult.IsCompleted}, IsCanceled:{flushResult.IsCanceled}"); //Log($"Reading..."); //var input = connection.Input; //while (true) //{ // Log($"Reading..."); // var readResult = await input.ReadAsync(); // Log($"IsCompleted:{readResult.IsCompleted}, IsCanceled:{readResult.IsCanceled}, Length:{readResult.Buffer.Length}"); // if (readResult.IsCompleted || readResult.IsCanceled) break; // if (readResult.Buffer.Length >= 36) // { // var buffer = readResult.Buffer; // var len = checked((int)buffer.Length); // var arr = ArrayPool<byte>.Shared.Rent(len); // try // { // buffer.CopyTo(arr); // var s = Encoding.UTF8.GetString(arr, 0, len); // Log($"Received: '{s}'"); // } // finally // { // ArrayPool<byte>.Shared.Return(arr); // } // input.AdvanceTo(readResult.Buffer.End); // break; // } // else // { // input.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); // } //} //Log($"Closing output..."); //output.Complete(); }
public async static Task HostServer() { var serverParams = ConsoleUI.UI.GetServerParameters(); EchoServer server = new EchoServer(serverParams.Item1, serverParams.Item2); await server.ListenAsync(); }
EchoServer StartServer(int port,int enableAcl,Dat acl) { var ip = TestUtil.CreateIp("127.0.0.1"); const int timeout = 300; var oneBind = new OneBind(ip, ProtocolKind.Tcp); var conf = TestUtil.CreateConf("OptionSample"); conf.Set("port", port); conf.Set("multiple", 10); conf.Set("acl", acl); conf.Set("enableAcl", enableAcl); conf.Set("timeOut", timeout); var sv = new EchoServer(conf, oneBind); sv.Start(); return sv; }
public void EchoサーバにstringSendで1行送信してstringRecvで1行受信する() { //setUp const string addr = "127.0.0.1"; const int port = 9993; var sv = new EchoServer(addr, port); sv.Start(); var sut = new SockTcp(new Kernel(),new Ip(addr), port, 100, null); sut.StringSend("本日は晴天なり", "UTF-8"); Thread.Sleep(10); var expected = "本日は晴天なり\r\n"; //exercise var actual = sut.StringRecv("UTF-8", 1, this); //verify Assert.That(actual, Is.EqualTo(expected)); //tearDown sut.Close(); sv.Stop(); }