Beispiel #1
0
        public void Listen(IPEndPoint localEndPoint)
        {
            if (_listener != null)
            {
                throw new InvalidOperationException("You cannot listen on a Tcp socket twice.");
            }
            _listener = new TcpListener(localEndPoint);
            _listener.Start();

            Task.Factory.StartNew(async() =>
            {
                try
                {
                    while (true)
                    {
                        var client = new TcpClientSocket(this,
                                                         await _listener.AcceptTcpClientAsync());
                    }
                }
                catch (InvalidOperationException)
                {
                    // The listener has not been started with a call to Start.
                    throw;
                }
                catch (SocketException ex)
                {
                    Debug.Write(ex);
                    Close();
                }
            });
        }
Beispiel #2
0
 public TcpSocketNotificationEventArgs(TcpClientSocket socket, int errorCode = 0)
 {
     Socket    = socket;
     ErrorCode = errorCode;
 }
Beispiel #3
0
 public TcpSocketReceiveEventArgs(TcpClientSocket socket, MessageStream message)
 {
     Socket = socket;
     Stream = message;
 }