Beispiel #1
0
        static void Main(string[] args)
        {
            encoding = Encoding.ASCII;
            SocketServer server;

            server = new SocketServer(new IPEndPoint(IPAddress.Loopback, 0));

            server.Connected.Subscribe(c =>
            {
                serverClient = new FramedClient(c);

                // When received is called, bs will contain no more and no less
                // data than whole packet as sent from client.
                serverClient.Received.Subscribe(bs =>
                {
                    var msg = encoding.GetString(bs.Array, bs.Offset, bs.Count);
                    msg     = "Hello, " + msg + "!";
                    serverClient.SendPacket(encoding.GetBytes(msg));
                });
            });

            server.Start();
            HandleClient(server.BindEndPoint.Port);

            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();

            server.Stop();
            client.Close();
            serverClient.Close();
        }
Beispiel #2
0
        private void FailWithExnAndClose(Exception exn)
        {
            handshakeCompleted.OnError(exn);
            disconnectedSubject.OnNext(exn);
            disconnectedSubject.OnCompleted();

            framedClient.Close();

            pingTimer.Change(Timeout.Infinite, Timeout.Infinite);
            pingTimer.Dispose();
        }