public void ServerStartUpTest() { var bootstrap = new ServerBootstrap(EndPointDispatcher.GetRandomPort()); Assert.IsTrue(bootstrap.StartUp()); var connector = new AsyncSocketConnector(); var future = connector.Connect(bootstrap.EndPoint); Assert.IsTrue(future.Await(500)); System.Threading.Thread.Sleep(500); Assert.AreEqual(1, bootstrap.Server.ManagedSessions.Count); Assert.IsTrue(future.Connected); Assert.IsNotNull(future.Session); bootstrap.Server.Dispose(); connector.Dispose(); }
static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine(typeof(Program).FullName + " <hostname> <port>"); return; } // Create TCP/IP connector. AsyncSocketConnector connector = new AsyncSocketConnector(); // Set connect timeout. connector.ConnectTimeoutInMillis = 30 * 1000L; // Set reader idle time to 10 seconds. // sessionIdle(...) method will be invoked when no data is read // for 10 seconds. connector.SessionOpened += (s, e) => e.Session.Config.SetIdleTime(IdleStatus.ReaderIdle, 10); // Print out total number of bytes read from the remote peer. connector.SessionClosed += (s, e) => Console.WriteLine("Total " + e.Session.ReadBytes + " byte(s)"); connector.SessionIdle += (s, e) => { if (e.IdleStatus == IdleStatus.ReaderIdle) e.Session.Close(true); }; connector.MessageReceived += (s, e) => { IoBuffer buf = (IoBuffer)e.Message; while (buf.HasRemaining) { Console.Write((Char)buf.Get()); } }; // Start communication. IConnectFuture cf = connector.Connect(new IPEndPoint(Dns.GetHostEntry(args[0]).AddressList[3], Int32.Parse(args[1]))); // Wait for the connection attempt to be finished. cf.Await(); cf.Session.CloseFuture.Await(); connector.Dispose(); }