Example #1
0
 void WriteDataSync(ISocket socket)
 {
     foreach (var d in MakeData())
     {
         Debug.WriteLine("Client writing data sync.");
         socket.Write(new ArraySegment <byte>(d), null);
     }
     Debug.WriteLine("Client ending connection.");
     socket.End();
 }
Example #2
0
        public void Simple_handshake_client_closes_connection()
        {
            serverDelegate.OnConnectionAction = (server, socket) =>
            {
                Debug.WriteLine("server OnConnection");
                serverSocketDelegate = new SocketDelegate();

                serverSocketDelegate.OnEndAction = () =>
                {
                    Debug.WriteLine("serverSocket OnEnd");
                    socket.End();
                };

                serverSocketDelegate.OnCloseAction = () =>
                {
                    Debug.WriteLine("serverSocket OnClose");
                    socket.Dispose();
                };

                return(serverSocketDelegate);
            };

            schedulerStartedAction = () =>
            {
                clientSocketDelegate.OnConnectedAction = () =>
                {
                    Debug.WriteLine("client End");
                    client.End();
                };
                clientSocketDelegate.OnCloseAction = () =>
                {
                    Debug.WriteLine("client OnClose");
                    scheduler.Stop();
                };

                client.Connect(ep);
            };

            RunScheduler();

            AssertConnectionAndCleanShutdown();
        }
Example #3
0
 // called if error on socket or whilst parsing, or if user code cancels request input
 public void OnError(Exception e)
 {
     if (tail == null)
     {
         socket.End();
     }
     else
     {
         // dispose all pending responses, last of which should end the socket
         tail.Dispose();
     }
 }
Example #4
0
        public void End_before_connect_throws_exception()
        {
            Exception ex = null;

            schedulerStartedAction = () =>
            {
                try
                {
                    client.End();
                }
                catch (InvalidOperationException e)
                {
                    ex = e;
                }
                scheduler.Stop();
            };

            RunScheduler();

            Assert.That(ex, Is.Not.Null);
            Assert.That(ex.Message, Is.EqualTo("The socket was not connected."));
        }
Example #5
0
 void WriteDataAsync(ISocket socket, IEnumerator <byte[]> ds)
 {
     if (ds.MoveNext())
     {
         Debug.WriteLine("Client writing data async.");
         if (!socket.Write(new ArraySegment <byte>(ds.Current), () => WriteDataAsync(socket, ds)))
         {
             WriteDataAsync(socket, ds);
         }
     }
     else
     {
         Debug.WriteLine("Client ending connection.");
         ds.Dispose();
         socket.End();
     }
 }
Example #6
0
 public void OnEnd()
 {
     socket.End();
 }
Example #7
0
 void WriteDataSync(ISocket socket)
 {
     foreach (var d in MakeData())
     {
         Debug.WriteLine("Client writing data sync.");
         socket.Write(new ArraySegment<byte>(d), null);
     }
     Debug.WriteLine("Client ending connection.");
     socket.End();
 }
Example #8
0
 void WriteDataAsync(ISocket socket, IEnumerator<byte[]> ds)
 {
     if (ds.MoveNext())
     {
         Debug.WriteLine("Client writing data async.");
         if (!socket.Write(new ArraySegment<byte>(ds.Current), () => WriteDataAsync(socket, ds)))
             WriteDataAsync(socket, ds);
     }
     else
     {
         Debug.WriteLine("Client ending connection.");
         ds.Dispose();
         socket.End();
     }
 }