コード例 #1
0
 /// <summary>
 /// Sets all variables to the closed state.
 /// </summary>
 private void ClosePrivate(ConnectionCloseReason reason, string message, Exception exception)
 {
     ConnectionAvailable = false;
     connectionLost      = true;
     Channel.Shutdown();
     FileTransfer?.Dispose(); // Cancel running file transfer
     OnConnectionClosed(reason, message, exception);
 }
コード例 #2
0
        protected virtual Task OnConnectionClosedAsync(ConnectionCloseReason connectionCloseReason)
        {
            if (m_IsDisposed || m_Runtime.IsDisposing || !m_Runtime.IsComponentAlive)
            {
                return(Task.CompletedTask);
            }

            return(m_EventBus.EmitAsync(m_Runtime, this, new RconClientDisconnectedEvent(this, connectionCloseReason)));
        }
コード例 #3
0
ファイル: RemoteClient.cs プロジェクト: skynet-im/vsl-net
        public override void OnConnectionClosed(ConnectionCloseReason reason, string message, Exception exception)
        {
            base.OnConnectionClosed(reason, message, exception);

            Interlocked.Increment(ref Program.Disconnects);
#if DEBUG
            Program.Log(vsl, message);
#endif
        }
コード例 #4
0
 public override void OnClose(ConnectionCloseReason reason)
 {
     try
     {
         netStream.Close();
         netStream = null;
     }
     catch (Exception)
     {
     }
 }
コード例 #5
0
        private void SendClose(ConnectionCloseReason connectionCloseReason)
        {
            List <byte> data = new List <byte>
            {
                0x80 | (byte)WebSocketOpcode.ConnectionClose,
                0x02,
                (byte)((int)connectionCloseReason >> 8),
                (byte)connectionCloseReason
            };

            Write(data.ToArray());
        }
コード例 #6
0
ファイル: RemoteTcpPeer.cs プロジェクト: lulzzz/AsyncNet
 /// <summary>
 /// Disconnects this peer/client
 /// </summary>
 /// <param name="reason">Disconnect reason</param>
 public virtual void Disconnect(ConnectionCloseReason reason)
 {
     try
     {
         this.connectionCloseReason = reason;
         this.cancellationTokenSource.Cancel();
     }
     catch (Exception)
     {
         return;
     }
 }
コード例 #7
0
ファイル: RemoteTcpPeer.cs プロジェクト: luwenyiCC/AsyncNet
 /// <summary>
 /// Disconnects this peer/client
 /// </summary>
 /// <param name="reason">Disconnect reason</param>
 public virtual void Disconnect(ConnectionCloseReason reason)
 {
     try
     {
         this.connectionCloseReason = reason;
         this.cancellationTokenSource.Cancel();
     }
     catch (Exception ex)
     {
         this.exceptionHandler?.Invoke(new RemoteTcpPeerExceptionEventArgs(this, ex));
         return;
     }
 }
コード例 #8
0
 /// <summary>
 /// Closes the TCP Connection and raises the related event.
 /// </summary>
 internal bool CloseInternal(ConnectionCloseReason reason, string message, Exception exception)
 {
     lock (connectionLostLock)
         if (!connectionLost) // To detect redundant calls
         {
             ClosePrivate(reason, message, exception);
             return(true);
         }
         else
         {
             return(false);
         }
 }
コード例 #9
0
ファイル: ConnectionBase.cs プロジェクト: windygu/ntlxproject
        public void Close(ConnectionCloseReason reason)
        {
            lock (this)
            {
                if (IsClosed)
                {
                    return;
                }
                IsClosed = true;

                EventRaiser.SoftRaiseEvent(Closed, this, new ConnectionCloseEventArgs(this, reason));

                OnClose(reason);
            }
        }
コード例 #10
0
        public void OnConnectionClosed(ConnectionCloseReason reason, string message, Exception exception)
        {
            if (!formClosing)
            {
                Invoke((MethodInvoker) delegate
                {
                    btnConnect.Enabled          = true;
                    btnConnect.Text             = "Verbinden";
                    btnClientSendPacket.Enabled = false;
                    btnReceiveFile.Enabled      = false;
                    btnSendFile.Enabled         = false;
                });
                clientConnected = false;
#if DEBUG
                Program.Log(vslClient, message);
#endif
            }
        }
コード例 #11
0
ファイル: LocalClient.cs プロジェクト: skynet-im/vsl-net
 public void OnConnectionClosed(ConnectionCloseReason reason, string message, Exception exception)
 {
 }
コード例 #12
0
 public ConnectionCloseEventArgs(ConnectionCloseReason connectionCloseReason)
 {
     ConnectionCloseReason = connectionCloseReason;
 }
コード例 #13
0
 public virtual void OnConnectionClosed(ConnectionCloseReason reason, string message, Exception exception)
 {
     logger.LogDebug("Connection closed: {0}", message);
     vsl.Dispose();
     ImmutableInterlocked.Update(ref Library.Clients, list => list.Remove(this));
 }
コード例 #14
0
 internal virtual void OnConnectionClosed(ConnectionCloseReason reason, string message, Exception exception)
 {
     callback.OnConnectionClosed(reason, message, exception);
 }
コード例 #15
0
ファイル: ConnectionBase.cs プロジェクト: windygu/ntlxproject
 public abstract void OnClose(ConnectionCloseReason reason);
コード例 #16
0
 public RconClientDisconnectedEvent(IRconClient client, ConnectionCloseReason connectionCloseReason) : base(client)
 {
     ConnectionCloseReason = connectionCloseReason;
 }
コード例 #17
0
 public ConnectionClosedData(IRemoteTcpPeer remoteTcpPeer, ConnectionCloseReason connectionCloseReason)
 {
     this.RemoteTcpPeer         = remoteTcpPeer;
     this.ConnectionCloseReason = connectionCloseReason;
 }
コード例 #18
0
        public void WebSocketServer_CloseConnection_Test()
        {
            var clientsCount = 1;
            var ipep         = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4445);
            var epList       = new List <TcpServerLocalEndpoint>
            {
                new TcpServerLocalEndpoint(ipep, clientsCount)
            };

            var s = new WebSocketServer();

            s.ConnectedEvent       += S_ConnectedEvent;
            s.DisconnectedEvent    += S_DisconnectedEvent;
            s.ConnectionCloseEvent += S_ConnectionCloseEvent;
            s.Start(epList);

            var c = new TcpClient();

            c.DataReceivedEvent += C_DataReceivedEvent;
            c.Start(ipep);
            var startTime = DateTime.Now;

            while (_connectionEventArgs == null)
            {
                var delta = DateTime.Now - startTime;
                if (delta.TotalSeconds > 10)
                {
                    Assert.Fail();
                }
                Thread.Sleep(1);
            }
            var         r   = new Random((int)DateTime.Now.Ticks);
            List <byte> key = new List <byte>();

            for (int i = 0; i < 16; i++)
            {
                key.Add((byte)r.Next(32, 127));
            }
            var keyStr = Convert.ToBase64String(key.ToArray());

            var reqStr = $"GET /Test HTTP/1.1\r\n";

            reqStr += "Upgrade: websocket\r\n";
            reqStr += "Connection: Upgrade\r\n";
            reqStr += $"Sec-WebSocket-Key: {keyStr}\r\n";
            reqStr += $"Sec-WebSocket-Version: 13\r\n\r\n";

            _handshakeTest     = true;
            _handshakeReceived = false;
            c.SendData(Encoding.UTF8.GetBytes(reqStr));
            startTime = DateTime.Now;
            while (_handshakeReceived == false)
            {
                var delta = DateTime.Now - startTime;
                if (delta.TotalSeconds > 10)
                {
                    Assert.Fail();
                }
                Thread.Sleep(1);
            }

            _handshakeTest = false;

            _clientFrameData.Clear();
            ConnectionCloseReason closeReason = ConnectionCloseReason.NormalClose;
            List <byte>           data        = new List <byte>();

            data.Add(0x80 | (byte)WebSocketOpcode.ConnectionClose);
            data.Add(0x02);
            data.Add((byte)((int)closeReason >> 8));
            data.Add((byte)closeReason);
            c.SendData(data.ToArray());

            startTime = DateTime.Now;
            _connectionCloseEventArgs = null;
            while (_clientFrameData.Count < 4)
            {
                var delta = DateTime.Now - startTime;
                if (delta.TotalSeconds > 10)
                {
                    Assert.Fail();
                }
                Thread.Sleep(1);
            }
            Assert.AreEqual(closeReason, _connectionCloseEventArgs?.ConnectionCloseReason);
            Assert.AreEqual(4, _clientFrameData.Count);

            var fin    = (_clientFrameData[0] & 0x80) >> 7;
            var opcode = (_clientFrameData[0] & 0x0F);

            Assert.AreEqual(0x01, fin);
            Assert.AreEqual(0x08, opcode);

            Assert.AreEqual(0x02, _clientFrameData[1]);
            Assert.AreEqual(0x03, _clientFrameData[2]);
            Assert.AreEqual(0xE8, _clientFrameData[3]);

            c.Dispose();
            s.Dispose();
        }
コード例 #19
0
 public ConnectionCloseEventArgs(IConnection connection, ConnectionCloseReason reason)
 {
     Connection = connection;
     Reason     = reason;
 }
コード例 #20
0
ファイル: VSLClient.cs プロジェクト: skynet-im/vsl-net
 internal override void OnConnectionClosed(ConnectionCloseReason reason, string message, Exception exception)
 {
     base.OnConnectionClosed(reason, message, exception);
     tcs?.SetResult(false);
 }