1212
1313namespace System . Net . WebSockets
1414{
15+ /// <summary>
16+ /// Describes the method that will handle the event that's fired when a message that has been subscribed to has been received.
17+ /// </summary>
18+ /// <param name="sender">The proximity device that received the message.</param>
19+ /// <param name="e">The proximity device that received the message.</param>
1520 public delegate void MessageReceivedEventHandler ( object sender , MessageReceivedEventArgs e ) ;
1621
1722 /// <summary>
@@ -20,7 +25,7 @@ namespace System.Net.WebSockets
2025 public class ClientWebSocket : WebSocket , IDisposable
2126 {
2227 private NetworkStream _networkStream ;
23-
28+
2429 private X509Certificate _certificate = null ;
2530
2631 /// <summary>
@@ -46,6 +51,9 @@ public class ClientWebSocket : WebSocket, IDisposable
4651 /// </summary>
4752 public string Host { get ; private set ; }
4853
54+ /// <summary>
55+ /// Option to use a custom certificate for authentication.
56+ /// </summary>
4957 public bool UseCustomCertificate => _certificate != null ;
5058
5159 /// <summary>
@@ -91,10 +99,10 @@ public X509Certificate CACertificate
9199 /// <param name="options">Optional <see cref="ClientWebSocketOptions"/> where extra options can be defined.</param>
92100 public ClientWebSocket ( ClientWebSocketOptions options = null ) : base ( options )
93101 {
94- if ( options != null )
102+ if ( options != null )
95103 {
96104 SslProtocol = options . SslProtocol ;
97- SslVerification = options . SslVerification ;
105+ SslVerification = options . SslVerification ;
98106 _certificate = options . Certificate ;
99107 }
100108 }
@@ -103,11 +111,10 @@ public ClientWebSocket(ClientWebSocketOptions options = null) : base(options)
103111 /// Connect to a WebSocket server.
104112 /// </summary>
105113 /// <param name="uri">The URI of the WebSocket server to connect to.</param>
106- /// <param name="messageReceivedHandler">A handler that is called when the WebSocket server receives a message</param>
107114 public void Connect ( string uri )
108115 {
109116 State = WebSocketFrame . WebSocketState . Connecting ;
110-
117+
111118 var splitUrl = uri . Split ( new char [ ] { ':' , '/' , '/' } , 4 ) ;
112119
113120 if ( splitUrl . Length == 4 && splitUrl [ 0 ] == "ws" )
@@ -161,6 +168,7 @@ public void Connect(string uri)
161168 _tcpSocket = new Socket ( AddressFamily . InterNetwork , SocketType . Stream , ProtocolType . Tcp ) ;
162169
163170 NetworkStream stream = null ;
171+
164172 try
165173 {
166174 _tcpSocket . Connect ( ep ) ;
@@ -204,9 +212,9 @@ private void WebSocket_ConnectionClosed(object sender, EventArgs e)
204212 _tcpSocket . Close ( ) ;
205213 }
206214
207- private void WebSocketClientConnect ( IPEndPoint remoteEndPoint , string prefix = "/" , string host = null )
215+ private void WebSocketClientConnect ( IPEndPoint remoteEndPoint , string prefix = "/" , string host = null )
208216 {
209- if ( prefix [ 0 ] != '/' ) throw new Exception ( "websocket prefix has to start with '/'" ) ;
217+ if ( prefix [ 0 ] != '/' ) throw new Exception ( "websocket prefix has to start with '/'" ) ;
210218
211219 byte [ ] keyBuf = new byte [ 16 ] ;
212220 new Random ( ) . NextBytes ( keyBuf ) ;
@@ -226,10 +234,10 @@ private void WebSocketClientConnect(IPEndPoint remoteEndPoint, string prefix = "
226234 if ( bytesRead == bufferStart . Length )
227235 {
228236 if ( Encoding . UTF8 . GetString ( bufferStart , 0 , bufferStart . Length ) . ToLower ( ) == beginHeader )
229- {
237+ {
230238 //right http request
231239 bytesRead = _networkStream . Read ( buffer , 0 , buffer . Length ) ;
232-
240+
233241 if ( bytesRead > 20 )
234242 {
235243 var headers = WebSocketHelpers . ParseHeaders ( Encoding . UTF8 . GetString ( buffer , 0 , bytesRead ) ) ;
0 commit comments