internal WebSocket(TcpListenerWebSocketContext context) : this() { _wsStream = context.Stream; _closeContext = () => context.Close(); init(context); }
private bool closeConnection() { _readyState = WsState.CLOSED; try { if (!_httpContext.IsNull()) { _httpContext.Response.Close(); _wsStream = null; _httpContext = null; } if (!_wsStream.IsNull()) { _wsStream.Dispose(); _wsStream = null; } if (!_tcpClient.IsNull()) { _tcpClient.Close(); _tcpClient = null; } return(true); } catch (Exception ex) { onError(ex.Message); return(false); } }
// As Client private void setClientStream() { var host = _uri.DnsSafeHost; var port = _uri.Port; _tcpClient = new TcpClient(host, port); _wsStream = WsStream.CreateClientStream(_tcpClient, host, _secure); }
// As Server private void closeResourcesAsServer() { if (!_context.IsNull() && !_closeContext.IsNull()) { _closeContext(); _wsStream = null; _context = null; } }
// As client private void init() { _base64key = createBase64Key(); var host = _uri.DnsSafeHost; var port = _uri.Port; _tcpClient = new TcpClient(host, port); _wsStream = WsStream.CreateClientStream(_tcpClient, host, _secure); }
// As Client private void createClientStream() { var host = _uri.DnsSafeHost; var port = _uri.Port > 0 ? _uri.Port : _isSecure ? 443 : 80; _tcpClient = new TcpClient(host, port); _wsStream = WsStream.CreateClientStream(_tcpClient, host, _isSecure); }
internal WebSocket(TcpListenerWebSocketContext context) : this() { _uri = context.Path.ToUri(); _context = context; _tcpClient = context.Client; _wsStream = context.Stream; _endPoint = context.ServerEndPoint; _isClient = false; _isSecure = context.IsSecureConnection; }
internal WebSocket(HttpListenerWebSocketContext context) : this() { _uri = Ext.ToUri(context.Path); _context = context; _httpContext = context.BaseContext; _wsStream = context.Stream; _endPoint = context.ServerEndPoint; _isClient = false; _isSecure = context.IsSecureConnection; }
// As Client private void closeResourcesAsClient() { if (!_wsStream.IsNull()) { _wsStream.Dispose(); _wsStream = null; } if (!_tcpClient.IsNull()) { _tcpClient.Close(); _tcpClient = null; } }
internal T ReadHandshake <T>(Func <string[], T> parser, int millisecondsTimeout) where T : HandshakeBase { bool timeout = false; Timer timer = new Timer(delegate(object state) { timeout = true; this._innerStream.Close(); }, null, millisecondsTimeout, -1); T result = (T)((object)null); Exception ex = null; try { result = parser(WsStream.readHandshakeHeaders(this._innerStream)); string text = result.Headers["Content-Length"]; if (text != null && text.Length > 0) { result.EntityBodyData = WsStream.readHandshakeEntityBody(this._innerStream, text); } } catch (Exception ex2) { ex = ex2; } finally { timer.Change(-1, -1); timer.Dispose(); } string text2 = (!timeout) ? ((ex == null) ? null : "An exception has occurred while receiving a handshake.") : "A timeout has occurred while receiving a handshake."; if (text2 != null) { throw new WebSocketException(text2, ex); } return(result); }
// As client private void closeClientResources() { if (_stream != null) { _stream.Dispose (); _stream = null; } if (_tcpClient != null) { _tcpClient.Close (); _tcpClient = null; } }
// As server private void closeResourcesAsServer() { if (!_context.IsNull() && !_closeContext.IsNull()) { _closeContext(); _wsStream = null; _context = null; } }
// As Client private void createClientStream() { var host = _uri.DnsSafeHost; var port = _uri.Port; if (port <= 0) port = IsSecure ? 443 : 80; _wsStream = WsStream.CreateClientStream(host, port, out _tcpClient); }
internal WebSocket(HttpListenerWebSocketContext context) : this() { _uri = context.Path.ToUri(); _context = context; _httpContext = context.BaseContext; _wsStream = context.Stream; _endPoint = context.ServerEndPoint; _isClient = false; _isSecure = context.IsSecureConnection; }
// As client private void closeResourcesAsClient() { if (!_wsStream.IsNull()) { _wsStream.Dispose(); _wsStream = null; } if (!_tcpClient.IsNull()) { _tcpClient.Close(); _tcpClient = null; } }
// As server private void closeResourcesAsServer() { if (_context != null && _closeContext != null) { _closeContext(); _wsStream = null; _context = null; } }
// As server private void closeServerResources() { if (_closeContext == null) return; _closeContext (); _closeContext = null; _stream = null; _context = null; }
// As client private bool closeClientResources() { try { if (_stream != null) { _stream.Dispose (); _stream = null; } if (_tcpClient != null) { _tcpClient.Close (); _tcpClient = null; } return true; } catch (Exception ex) { _logger.Fatal (ex.ToString ()); error ("An exception has occurred."); return false; } }
// As client private void setClientStream() { var host = _uri.DnsSafeHost; var port = _uri.Port; _tcpClient = new TcpClient (host, port); _stream = WsStream.CreateClientStream (_tcpClient, _secure, host, _certValidationCallback); }
// As server private void closeServerResources() { if (_context != null && _closeContext != null) { _closeContext (); _stream = null; _context = null; } }
private bool closeConnection() { _readyState = WsState.CLOSED; try { if (_httpContext != null) { _httpContext.Response.Close(); _wsStream = null; _httpContext = null; } if (_wsStream != null) { _wsStream.Dispose(); _wsStream = null; } if (_tcpClient != null) { _tcpClient.Close(); _tcpClient = null; } return true; } catch (Exception ex) { onError(ex.Message); return false; } }
internal WebSocket(TcpListenerWebSocketContext context) : this() { _uri = Ext.ToUri(context.Path); _context = context; _tcpClient = context.Client; _wsStream = context.Stream; _endPoint = context.ServerEndPoint; _isClient = false; _isSecure = context.IsSecureConnection; }
// As server internal WebSocket(TcpListenerWebSocketContext context, Logger logger) { _context = context; _logger = logger; _closeContext = context.Close; _secure = context.IsSecureConnection; _stream = context.Stream; _uri = context.Path.ToUri (); init (); }
// As server private bool closeServerResources() { try { if (_closeContext != null) _closeContext (); _stream = null; _context = null; return true; } catch (Exception ex) { _logger.Fatal (ex.ToString ()); error ("An exception has occurred."); return false; } }
// As client private void closeResourcesAsClient() { if (_wsStream != null) { _wsStream.Dispose(); _wsStream = null; } if (_tcpClient != null) { _tcpClient.Close(); _tcpClient = null; } }
internal WebSocket(TcpListenerWebSocketContext context) : this() { _stream = context.Stream; _closeContext = () => context.Close (); init (context); }
internal const int FragmentLength = 1016; // Max value is int.MaxValue - 14. #endregion #region Internal Constructors // As server internal WebSocket (HttpListenerWebSocketContext context, Logger logger) { _context = context; _logger = logger; _closeContext = context.Close; _secure = context.IsSecureConnection; _stream = context.Stream; _uri = context.RequestUri; init (); }