コード例 #1
0
        public virtual void Dispose()
        {
            // send special web socket close message. Don't close the network stream, it will be disposed later
            try
            {
                if (!_isDisposed)
                {
                    _isDisposed = true;
                }
            }
            catch (Exception ex)
            {
            }

            try
            {
                if (_frameBuilder != null)
                {
                    _frameBuilder.Dispose();
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #2
0
ファイル: WebSocketClient.cs プロジェクト: kruthikk/Websocket
        private void WaitForServerCloseMessage()
        {
            try
            {
                // as per the websocket spec, the server must close the connection, not the client.
                // The client is free to close the connection after a timeout period if the server fails to do so
                //_conectionCloseWait.WaitOne(TimeSpan.FromSeconds(10));

                // this will only happen if the server has failed to reply with a close response
                var isOpen = false;
                lock (connectSync)
                {
                    isOpen = _isOpen;
                }

                if (isOpen)
                {
                    //_logger.Warn("Server failed to respond with a close response. Closing the connection from the client side.");

                    // wait for data to be sent before we close the stream and client

                    try
                    {
                        _tcpClient.Client.Shutdown(SocketShutdown.Both);
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        _stream.Close();
                    }
                    catch (Exception ex)
                    {
                    }
                    try
                    {
                        _tcpClient.Close();
                    }
                    catch (Exception ex)
                    {
                    }

                    if (_frameBuilder != null)
                    {
                        _frameBuilder.Dispose();
                    }
                }

                _logger.Info("Client: Connection closed");
            }
            catch
            {
            }
        }