diff --git a/Example/Example.pidb b/Example/Example.pidb index 7fe02fa9..78ebcb67 100644 Binary files a/Example/Example.pidb and b/Example/Example.pidb differ diff --git a/Example/bin/Debug/example.exe b/Example/bin/Debug/example.exe index e2cec72d..15b5c777 100755 Binary files a/Example/bin/Debug/example.exe and b/Example/bin/Debug/example.exe differ diff --git a/Example/bin/Debug/example.exe.mdb b/Example/bin/Debug/example.exe.mdb index 88f9473f..c2e82532 100644 Binary files a/Example/bin/Debug/example.exe.mdb and b/Example/bin/Debug/example.exe.mdb differ diff --git a/Example/bin/Debug/websocket-sharp.dll b/Example/bin/Debug/websocket-sharp.dll index 431b9c16..50e04bf5 100755 Binary files a/Example/bin/Debug/websocket-sharp.dll and b/Example/bin/Debug/websocket-sharp.dll differ diff --git a/Example/bin/Debug/websocket-sharp.dll.mdb b/Example/bin/Debug/websocket-sharp.dll.mdb index c9ec20ff..e38f9cb9 100644 Binary files a/Example/bin/Debug/websocket-sharp.dll.mdb and b/Example/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index 82f91787..7a9e6b21 100755 Binary files a/Example/bin/Debug_Ubuntu/example.exe and b/Example/bin/Debug_Ubuntu/example.exe differ diff --git a/Example/bin/Debug_Ubuntu/example.exe.mdb b/Example/bin/Debug_Ubuntu/example.exe.mdb index 16443663..4c881ada 100644 Binary files a/Example/bin/Debug_Ubuntu/example.exe.mdb and b/Example/bin/Debug_Ubuntu/example.exe.mdb differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index 5d5fa248..0b4a51ac 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 0803f12c..a61290ec 100644 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example/bin/Release/example.exe b/Example/bin/Release/example.exe index 43a13b64..08582618 100755 Binary files a/Example/bin/Release/example.exe and b/Example/bin/Release/example.exe differ diff --git a/Example/bin/Release/websocket-sharp.dll b/Example/bin/Release/websocket-sharp.dll index 37bc66e7..a38c65bd 100755 Binary files a/Example/bin/Release/websocket-sharp.dll and b/Example/bin/Release/websocket-sharp.dll differ diff --git a/Example/bin/Release_Ubuntu/example.exe b/Example/bin/Release_Ubuntu/example.exe index 760ee9f8..4cbeab44 100755 Binary files a/Example/bin/Release_Ubuntu/example.exe and b/Example/bin/Release_Ubuntu/example.exe differ diff --git a/Example/bin/Release_Ubuntu/websocket-sharp.dll b/Example/bin/Release_Ubuntu/websocket-sharp.dll index 393f4f9a..9ca89d17 100755 Binary files a/Example/bin/Release_Ubuntu/websocket-sharp.dll and b/Example/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug/example1.exe b/Example1/bin/Debug/example1.exe index 3e7fb7a7..a3bcab9b 100755 Binary files a/Example1/bin/Debug/example1.exe and b/Example1/bin/Debug/example1.exe differ diff --git a/Example1/bin/Debug/example1.exe.mdb b/Example1/bin/Debug/example1.exe.mdb index ab1b79a9..5f5235a9 100644 Binary files a/Example1/bin/Debug/example1.exe.mdb and b/Example1/bin/Debug/example1.exe.mdb differ diff --git a/Example1/bin/Debug/websocket-sharp.dll b/Example1/bin/Debug/websocket-sharp.dll index 431b9c16..50e04bf5 100755 Binary files a/Example1/bin/Debug/websocket-sharp.dll and b/Example1/bin/Debug/websocket-sharp.dll differ diff --git a/Example1/bin/Debug/websocket-sharp.dll.mdb b/Example1/bin/Debug/websocket-sharp.dll.mdb index c9ec20ff..e38f9cb9 100644 Binary files a/Example1/bin/Debug/websocket-sharp.dll.mdb and b/Example1/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index d107f8ea..fad2ead3 100755 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe and b/Example1/bin/Debug_Ubuntu/example1.exe differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe.mdb b/Example1/bin/Debug_Ubuntu/example1.exe.mdb index cbc75fda..48f0f420 100644 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe.mdb and b/Example1/bin/Debug_Ubuntu/example1.exe.mdb differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index 5d5fa248..0b4a51ac 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 0803f12c..a61290ec 100644 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example1/bin/Release/example1.exe b/Example1/bin/Release/example1.exe index 83f6bafe..1e65872e 100755 Binary files a/Example1/bin/Release/example1.exe and b/Example1/bin/Release/example1.exe differ diff --git a/Example1/bin/Release/websocket-sharp.dll b/Example1/bin/Release/websocket-sharp.dll index 37bc66e7..a38c65bd 100755 Binary files a/Example1/bin/Release/websocket-sharp.dll and b/Example1/bin/Release/websocket-sharp.dll differ diff --git a/Example1/bin/Release_Ubuntu/example1.exe b/Example1/bin/Release_Ubuntu/example1.exe index 3dc27c2d..7bd37551 100755 Binary files a/Example1/bin/Release_Ubuntu/example1.exe and b/Example1/bin/Release_Ubuntu/example1.exe differ diff --git a/Example1/bin/Release_Ubuntu/websocket-sharp.dll b/Example1/bin/Release_Ubuntu/websocket-sharp.dll index 393f4f9a..9ca89d17 100755 Binary files a/Example1/bin/Release_Ubuntu/websocket-sharp.dll and b/Example1/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/Example2.pidb b/Example2/Example2.pidb index 8dfcf1b3..7da842f1 100644 Binary files a/Example2/Example2.pidb and b/Example2/Example2.pidb differ diff --git a/Example2/bin/Debug/example2.exe b/Example2/bin/Debug/example2.exe index a312f5c1..ea2b11a9 100755 Binary files a/Example2/bin/Debug/example2.exe and b/Example2/bin/Debug/example2.exe differ diff --git a/Example2/bin/Debug/example2.exe.mdb b/Example2/bin/Debug/example2.exe.mdb index d8e1c542..b056b943 100644 Binary files a/Example2/bin/Debug/example2.exe.mdb and b/Example2/bin/Debug/example2.exe.mdb differ diff --git a/Example2/bin/Debug/websocket-sharp.dll b/Example2/bin/Debug/websocket-sharp.dll index 431b9c16..50e04bf5 100755 Binary files a/Example2/bin/Debug/websocket-sharp.dll and b/Example2/bin/Debug/websocket-sharp.dll differ diff --git a/Example2/bin/Debug/websocket-sharp.dll.mdb b/Example2/bin/Debug/websocket-sharp.dll.mdb index c9ec20ff..e38f9cb9 100644 Binary files a/Example2/bin/Debug/websocket-sharp.dll.mdb and b/Example2/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 109cde99..8f4222fe 100755 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe and b/Example2/bin/Debug_Ubuntu/example2.exe differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe.mdb b/Example2/bin/Debug_Ubuntu/example2.exe.mdb index 86e4dfa4..326137ac 100644 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe.mdb and b/Example2/bin/Debug_Ubuntu/example2.exe.mdb differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index 5d5fa248..0b4a51ac 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 0803f12c..a61290ec 100644 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example2/bin/Release/example2.exe b/Example2/bin/Release/example2.exe index a4aeb68c..d2f23b5a 100755 Binary files a/Example2/bin/Release/example2.exe and b/Example2/bin/Release/example2.exe differ diff --git a/Example2/bin/Release/websocket-sharp.dll b/Example2/bin/Release/websocket-sharp.dll index 37bc66e7..a38c65bd 100755 Binary files a/Example2/bin/Release/websocket-sharp.dll and b/Example2/bin/Release/websocket-sharp.dll differ diff --git a/Example2/bin/Release_Ubuntu/example2.exe b/Example2/bin/Release_Ubuntu/example2.exe index 7af43297..43c2abe2 100755 Binary files a/Example2/bin/Release_Ubuntu/example2.exe and b/Example2/bin/Release_Ubuntu/example2.exe differ diff --git a/Example2/bin/Release_Ubuntu/websocket-sharp.dll b/Example2/bin/Release_Ubuntu/websocket-sharp.dll index 393f4f9a..9ca89d17 100755 Binary files a/Example2/bin/Release_Ubuntu/websocket-sharp.dll and b/Example2/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug/Example3.exe b/Example3/bin/Debug/Example3.exe index 21a7cbdd..2a860d34 100755 Binary files a/Example3/bin/Debug/Example3.exe and b/Example3/bin/Debug/Example3.exe differ diff --git a/Example3/bin/Debug/Example3.exe.mdb b/Example3/bin/Debug/Example3.exe.mdb index 3244c62b..c781d750 100644 Binary files a/Example3/bin/Debug/Example3.exe.mdb and b/Example3/bin/Debug/Example3.exe.mdb differ diff --git a/Example3/bin/Debug/websocket-sharp.dll b/Example3/bin/Debug/websocket-sharp.dll index 431b9c16..50e04bf5 100755 Binary files a/Example3/bin/Debug/websocket-sharp.dll and b/Example3/bin/Debug/websocket-sharp.dll differ diff --git a/Example3/bin/Debug/websocket-sharp.dll.mdb b/Example3/bin/Debug/websocket-sharp.dll.mdb index c9ec20ff..e38f9cb9 100644 Binary files a/Example3/bin/Debug/websocket-sharp.dll.mdb and b/Example3/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index 411dce92..6c4d7793 100755 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe and b/Example3/bin/Debug_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb index 0604a51d..78f41dd6 100644 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe.mdb and b/Example3/bin/Debug_Ubuntu/Example3.exe.mdb differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index 5d5fa248..0b4a51ac 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 0803f12c..a61290ec 100644 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/Example3/bin/Release/Example3.exe b/Example3/bin/Release/Example3.exe index 470666d1..389e1a90 100755 Binary files a/Example3/bin/Release/Example3.exe and b/Example3/bin/Release/Example3.exe differ diff --git a/Example3/bin/Release/websocket-sharp.dll b/Example3/bin/Release/websocket-sharp.dll index 37bc66e7..a38c65bd 100755 Binary files a/Example3/bin/Release/websocket-sharp.dll and b/Example3/bin/Release/websocket-sharp.dll differ diff --git a/Example3/bin/Release_Ubuntu/Example3.exe b/Example3/bin/Release_Ubuntu/Example3.exe index bf0bce4d..9c3da218 100755 Binary files a/Example3/bin/Release_Ubuntu/Example3.exe and b/Example3/bin/Release_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Release_Ubuntu/websocket-sharp.dll b/Example3/bin/Release_Ubuntu/websocket-sharp.dll index 393f4f9a..9ca89d17 100755 Binary files a/Example3/bin/Release_Ubuntu/websocket-sharp.dll and b/Example3/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/Ext.cs b/websocket-sharp/Ext.cs index 534f5869..878d8603 100644 --- a/websocket-sharp/Ext.cs +++ b/websocket-sharp/Ext.cs @@ -82,15 +82,18 @@ namespace WebSocketSharp { /// /// A that contains a TCP connection to accept a WebSocket connection from. /// + /// + /// A that indicates a secure connection or not. (true indicates a secure connection.) + /// /// /// Is thrown when the parameter passed to a method is invalid because it is . /// - public static TcpListenerWebSocketContext AcceptWebSocket(this TcpClient client) + public static TcpListenerWebSocketContext AcceptWebSocket(this TcpClient client, bool secure) { if (client.IsNull()) throw new ArgumentNullException("client"); - return new TcpListenerWebSocketContext(client); + return new TcpListenerWebSocketContext(client, secure); } /// diff --git a/websocket-sharp/Net/Sockets/TcpListenerWebSocketContext.cs b/websocket-sharp/Net/Sockets/TcpListenerWebSocketContext.cs index 41dc09fc..00179863 100644 --- a/websocket-sharp/Net/Sockets/TcpListenerWebSocketContext.cs +++ b/websocket-sharp/Net/Sockets/TcpListenerWebSocketContext.cs @@ -43,11 +43,11 @@ namespace WebSocketSharp.Net.Sockets { private WebSocket _socket; private WsStream _stream; - internal TcpListenerWebSocketContext(TcpClient client) + internal TcpListenerWebSocketContext(TcpClient client, bool secure) { _client = client; - _stream = WsStream.CreateServerStream(client); - _isSecure = _stream.IsSecure; + _isSecure = secure; + _stream = WsStream.CreateServerStream(client, secure); _request = RequestHandshake.Parse(_stream.ReadHandshake()); _socket = new WebSocket(this); } diff --git a/websocket-sharp/Server/WebSocketServer.cs b/websocket-sharp/Server/WebSocketServer.cs index 8cc96cb5..5d84e432 100644 --- a/websocket-sharp/Server/WebSocketServer.cs +++ b/websocket-sharp/Server/WebSocketServer.cs @@ -67,8 +67,18 @@ namespace WebSocketSharp.Server { init(); } + public WebSocketServer(int port, bool secure) + : this(System.Net.IPAddress.Any, port, secure) + { + } + public WebSocketServer(System.Net.IPAddress address, int port) - : base(address, port) + : this(address, port, port == 443 ? true : false) + { + } + + public WebSocketServer(System.Net.IPAddress address, int port, bool secure) + : base(address, port, "/", secure) { init(); } @@ -112,7 +122,7 @@ namespace WebSocketSharp.Server { protected override void AcceptWebSocket(TcpClient client) { - var context = client.AcceptWebSocket(); + var context = client.AcceptWebSocket(IsSecure); var socket = context.WebSocket; var path = context.Path.UrlDecode(); diff --git a/websocket-sharp/Server/WebSocketServerBase.cs b/websocket-sharp/Server/WebSocketServerBase.cs index 7f658ab7..351c6f1c 100644 --- a/websocket-sharp/Server/WebSocketServerBase.cs +++ b/websocket-sharp/Server/WebSocketServerBase.cs @@ -40,6 +40,7 @@ namespace WebSocketSharp.Server { private Thread _acceptClientThread; private IPAddress _address; + private bool _isSecure; private bool _isSelfHost; private int _port; private TcpListener _tcpListener; @@ -67,12 +68,7 @@ namespace WebSocketSharp.Server { init(uri); } - protected WebSocketServerBase(IPAddress address, int port) - : this(address, port, "/") - { - } - - protected WebSocketServerBase(IPAddress address, int port, string absPath) + protected WebSocketServerBase(IPAddress address, int port, string absPath, bool secure) { if (address.IsNull()) throw new ArgumentNullException("address"); @@ -84,9 +80,20 @@ namespace WebSocketSharp.Server { if (!absPath.IsValidAbsolutePath(out msg)) throw new ArgumentException(msg, "absPath"); - _address = address; - _port = port <= 0 ? 80 : port; - _uri = absPath.ToUri(); + if ((port == 80 && secure) || + (port == 443 && !secure)) + { + msg = String.Format( + "Invalid pair of 'port' and 'secure': {0}, {1}", port, secure); + throw new ArgumentException(msg); + } + + _address = address; + _port = port > 0 + ? port + : secure ? 443 : 80; + _uri = absPath.ToUri(); + _isSecure = secure; init(); } @@ -116,6 +123,12 @@ namespace WebSocketSharp.Server { } } + public bool IsSecure { + get { + return _isSecure; + } + } + public bool IsSelfHost { get { return _isSelfHost; @@ -185,17 +198,17 @@ namespace WebSocketSharp.Server { private void init(Uri uri) { - _uri = uri; var scheme = uri.Scheme; - var port = uri.Port; var host = uri.DnsSafeHost; + var port = uri.Port; var addrs = Dns.GetHostAddresses(host); - if (port <= 0) - port = scheme == "ws" ? 80 : 443; - - _address = addrs[0]; - _port = port; + _uri = uri; + _address = addrs[0]; + _isSecure = scheme == "wss" ? true : false; + _port = port > 0 + ? port + : _isSecure ? 443 : 80; init(); } @@ -234,7 +247,7 @@ namespace WebSocketSharp.Server { #endregion - #region Protected Method + #region Protected Methods protected abstract void AcceptWebSocket(TcpClient client); diff --git a/websocket-sharp/Server/WebSocketServiceHost.cs b/websocket-sharp/Server/WebSocketServiceHost.cs index 5132453c..88d3d0b3 100644 --- a/websocket-sharp/Server/WebSocketServiceHost.cs +++ b/websocket-sharp/Server/WebSocketServiceHost.cs @@ -66,13 +66,28 @@ namespace WebSocketSharp.Server { init(); } + public WebSocketServiceHost(int port, bool secure) + : this(port, "/", secure) + { + } + public WebSocketServiceHost(int port, string absPath) : this(System.Net.IPAddress.Any, port, absPath) { } + public WebSocketServiceHost(int port, string absPath, bool secure) + : this(System.Net.IPAddress.Any, port, absPath, secure) + { + } + public WebSocketServiceHost(System.Net.IPAddress address, int port, string absPath) - : base(address, port, absPath) + : this(address, port, absPath, port == 443 ? true : false) + { + } + + public WebSocketServiceHost(System.Net.IPAddress address, int port, string absPath, bool secure) + : base(address, port, absPath, secure) { init(); } @@ -116,7 +131,7 @@ namespace WebSocketSharp.Server { protected override void AcceptWebSocket(TcpClient client) { - var context = client.AcceptWebSocket(); + var context = client.AcceptWebSocket(IsSecure); var socket = context.WebSocket; var path = context.Path.UrlDecode(); if (path != Uri.GetAbsolutePath().UrlDecode()) diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index fd6f3ff2..5c001eef 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -515,11 +515,12 @@ namespace WebSocketSharp { private void createClientStream() { var host = _uri.DnsSafeHost; - var port = _uri.Port; - if (port <= 0) - port = IsSecure ? 443 : 80; + var port = _uri.Port > 0 + ? _uri.Port + : _isSecure ? 443 : 80; - _wsStream = WsStream.CreateClientStream(host, port, out _tcpClient); + _tcpClient = new TcpClient(host, port); + _wsStream = WsStream.CreateClientStream(_tcpClient, host, _isSecure); } private WsFrame createFrame(Fin fin, Opcode opcode, PayloadData payloadData) @@ -1046,7 +1047,7 @@ namespace WebSocketSharp { var count = rem == 0 ? quo - 2 : quo - 1; // First - var buffer = new byte[_fragmentLen]; + var buffer = new byte[_fragmentLen]; long readLen = stream.Read(buffer, 0, _fragmentLen); send(Fin.MORE, opcode, buffer); diff --git a/websocket-sharp/WsStream.cs b/websocket-sharp/WsStream.cs index 3cb83b59..cdd5ba41 100644 --- a/websocket-sharp/WsStream.cs +++ b/websocket-sharp/WsStream.cs @@ -44,23 +44,42 @@ namespace WebSocketSharp { #region Fields private Stream _innerStream; - private Type _innerStreamType; private bool _isSecure; private Object _forRead; private Object _forWrite; #endregion - #region Constructors + #region Private Constructor + + private WsStream() + { + _forRead = new object(); + _forWrite = new object(); + } + + #endregion + + #region Public Constructors public WsStream(NetworkStream innerStream) + : this() { - init(innerStream); + if (innerStream.IsNull()) + throw new ArgumentNullException("innerStream"); + + _innerStream = innerStream; + _isSecure = false; } public WsStream(SslStream innerStream) + : this() { - init(innerStream); + if (innerStream.IsNull()) + throw new ArgumentNullException("innerStream"); + + _innerStream = innerStream; + _isSecure = true; } #endregion @@ -69,7 +88,7 @@ namespace WebSocketSharp { public bool DataAvailable { get { - return _innerStreamType == typeof(SslStream) + return _isSecure ? ((SslStream)_innerStream).DataAvailable : ((NetworkStream)_innerStream).DataAvailable; } @@ -83,26 +102,14 @@ namespace WebSocketSharp { #endregion - #region Private Method - - private void init(Stream innerStream) - { - if (innerStream == null) - throw new ArgumentNullException("innerStream"); - - _innerStream = innerStream; - _innerStreamType = innerStream.GetType(); - _isSecure = _innerStreamType == typeof(SslStream) ? true : false; - _forRead = new object(); - _forWrite = new object(); - } + #region Private Methods private int read(byte[] buffer, int offset, int size) { var readLen = _innerStream.Read(buffer, offset, size); if (readLen < size) { - var msg = String.Format("Data can not be read from {0}.", _innerStreamType); + var msg = String.Format("Data can not be read from {0}.", _innerStream.GetType().Name); throw new IOException(msg); } @@ -145,12 +152,10 @@ namespace WebSocketSharp { #region Internal Methods - internal static WsStream CreateClientStream(string hostname, int port, out TcpClient client) + internal static WsStream CreateClientStream(TcpClient client, string host, bool secure) { - client = new TcpClient(hostname, port); var netStream = client.GetStream(); - - if (port == 443) + if (secure) { System.Net.Security.RemoteCertificateValidationCallback validationCb = (sender, certificate, chain, sslPolicyErrors) => { @@ -159,7 +164,7 @@ namespace WebSocketSharp { }; var sslStream = new SslStream(netStream, false, validationCb); - sslStream.AuthenticateAsClient(hostname); + sslStream.AuthenticateAsClient(host); return new WsStream(sslStream); } @@ -167,16 +172,13 @@ namespace WebSocketSharp { return new WsStream(netStream); } - internal static WsStream CreateServerStream(TcpClient client) + internal static WsStream CreateServerStream(TcpClient client, bool secure) { var netStream = client.GetStream(); - - var port = ((IPEndPoint)client.Client.LocalEndPoint).Port; - if (port == 443) + if (secure) { var sslStream = new SslStream(netStream, false); - - var certPath = ConfigurationManager.AppSettings["ServerCertPath"]; + var certPath = ConfigurationManager.AppSettings["ServerCertPath"]; sslStream.AuthenticateAsServer(new X509Certificate2(certPath)); return new WsStream(sslStream); diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll b/websocket-sharp/bin/Debug/websocket-sharp.dll index 431b9c16..50e04bf5 100755 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll and b/websocket-sharp/bin/Debug/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb index c9ec20ff..e38f9cb9 100644 Binary files a/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 5d5fa248..0b4a51ac 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb index 0803f12c..a61290ec 100644 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll.mdb differ diff --git a/websocket-sharp/bin/Release/websocket-sharp.dll b/websocket-sharp/bin/Release/websocket-sharp.dll index 37bc66e7..a38c65bd 100755 Binary files a/websocket-sharp/bin/Release/websocket-sharp.dll and b/websocket-sharp/bin/Release/websocket-sharp.dll differ diff --git a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll index 393f4f9a..9ca89d17 100755 Binary files a/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/websocket-sharp.pidb b/websocket-sharp/websocket-sharp.pidb index 03e85f14..3e9e004c 100644 Binary files a/websocket-sharp/websocket-sharp.pidb and b/websocket-sharp/websocket-sharp.pidb differ