diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 65390cdc..48f56129 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -122,20 +122,30 @@ namespace WebSocketSharp #region Internal Constructors + // As server internal WebSocket (HttpListenerWebSocketContext context, Logger logger) : this () { - _stream = context.Stream; + _context = context; + _logger = logger; + _closeContext = context.Close; - init (context, logger); + _secure = context.IsSecureConnection; + _stream = context.Stream; + _uri = context.RequestUri; } + // As server internal WebSocket (TcpListenerWebSocketContext context, Logger logger) : this () { - _stream = context.Stream; + _context = context; + _logger = logger; + _closeContext = context.Close; - init (context, logger); + _secure = context.IsSecureConnection; + _stream = context.Stream; + _uri = context.RequestUri; } #endregion @@ -147,18 +157,18 @@ namespace WebSocketSharp /// specified WebSocket URL and subprotocols. /// /// - /// A that contains a WebSocket URL to connect. + /// A that represents the WebSocket URL to connect. /// /// /// An array of that contains the WebSocket subprotocols /// if any. /// - /// - /// is . - /// /// /// is invalid. /// + /// + /// is . + /// public WebSocket (string url, params string[] protocols) : this () { @@ -170,61 +180,11 @@ namespace WebSocketSharp throw new ArgumentException (msg, "url"); _protocols = protocols.ToString (", "); - _secure = _uri.Scheme == "wss" ? true : false; - _client = true; + _base64key = createBase64Key (); + _client = true; _logger = new Logger (); - } - - /// - /// Initializes a new instance of the class with the - /// specified WebSocket URL, OnOpen, OnMessage, OnError, OnClose event - /// handlers and subprotocols. - /// - /// - /// This constructor initializes a new instance of the - /// class and establishes a WebSocket connection. - /// - /// - /// A that contains a WebSocket URL to connect. - /// - /// - /// An event handler. - /// - /// - /// An event handler. - /// - /// - /// An event handler. - /// - /// - /// An event handler. - /// - /// - /// An array of that contains the WebSocket subprotocols - /// if any. - /// - /// - /// is . - /// - /// - /// is invalid. - /// - public WebSocket ( - string url, - EventHandler onOpen, - EventHandler onMessage, - EventHandler onError, - EventHandler onClose, - params string [] protocols) - : this (url, protocols) - { - OnOpen = onOpen; - OnMessage = onMessage; - OnError = onError; - OnClose = onClose; - - Connect (); + _secure = _uri.Scheme == "wss"; } #endregion @@ -850,15 +810,6 @@ namespace WebSocketSharp OnError.Emit (this, new ErrorEventArgs (message)); } - // As server - private void init (WebSocketContext context, Logger logger) - { - _context = context; - _logger = logger; - _uri = context.RequestUri; - _secure = context.IsSecureConnection; - } - private void open () { _readyState = WebSocketState.OPEN;