public static LoadFromString ( string value ) : |
||
value | string | |
return |
/// <summary> /// <para>Client performs an initial HTTP POST to obtain a SessionId (sid) assigned to a client, followed /// by the heartbeat timeout, connection closing timeout, and the list of supported transports.</para> /// <para>The tansport and sid are required as part of the ws: transport connection</para> /// </summary> /// <param name="uri">http://localhost:3000</param> /// <returns>Handshake object with sid value</returns> /// <example>DownloadString: 13052140081337757257:15:25:websocket,htmlfile,xhr-polling,jsonp-polling</example> protected SocketIOHandshake requestHandshake(Uri uri) { string value = string.Empty; string errorText = string.Empty; SocketIOHandshake handshake = null; using (WebClient client = new WebClient()) { try { value = client.DownloadString(string.Format("{0}://{1}:{2}/socket.io/1/{3}", uri.Scheme, uri.Host, uri.Port, uri.Query)); // #5 tkiley: The uri.Query is available in socket.io's handshakeData object during authorization // 13052140081337757257:15:25:websocket,htmlfile,xhr-polling,jsonp-polling if (string.IsNullOrEmpty(value)) { errorText = "Did not receive handshake string from server"; } } catch (Exception ex) { errorText = string.Format("Error getting handsake from Socket.IO host instance: {0}", ex.Message); //this.OnErrorEvent(this, new ErrorEventArgs(errMsg)); } } if (string.IsNullOrEmpty(errorText)) { handshake = SocketIOHandshake.LoadFromString(value); } else { handshake = new SocketIOHandshake(); handshake.ErrorMessage = errorText; } return(handshake); }
/// <summary> /// <para>Client performs an initial HTTP POST to obtain a SessionId (sid) assigned to a client, followed /// by the heartbeat timeout, connection closing timeout, and the list of supported transports.</para> /// <para>The tansport and sid are required as part of the ws: transport connection</para> /// </summary> /// <param name="uri">http://localhost:3000</param> /// <returns>Handshake object with sid value</returns> /// <example>DownloadString: 13052140081337757257:15:25:websocket,htmlfile,xhr-polling,jsonp-polling</example> protected SocketIOHandshake requestHandshake(Uri uri) { string value = string.Empty; string errorText = string.Empty; SocketIOHandshake handshake = null; using (WebClient client = new WebClient()) { try { var url = string.Format("{0}://{1}:{2}/socket.io/{3}", uri.Scheme, uri.Host, uri.Port, uri.Query); client.Headers.Add("Upgrade", "websocket"); client.Headers.Add("Connection", "Upgrade"); client.Headers.Add("Sec-Websocket-Version", "13"); client.Headers.Add("Sec-WebSocket-Key", "Lp2qSYxx3lHnGHdwFyHKQA=="); value = client.DownloadString(url); // #5 tkiley: The uri.Query is available in socket.io's handshakeData object during authorization //value = client.ResponseHeaders.Get("Sec-WebSocket-Accept"); // 13052140081337757257:15:25:websocket,htmlfile,xhr-polling,jsonp-polling if (string.IsNullOrEmpty(value)) { errorText = "Did not receive handshake string from server"; } } catch (Exception ex) { errorText = string.Format("Error getting handsake from Socket.IO host instance: {0}", ex.Message); //this.OnErrorEvent(this, new ErrorEventArgs(errMsg)); } } if (string.IsNullOrEmpty(errorText)) { handshake = SocketIOHandshake.LoadFromString(value); } else { handshake = new SocketIOHandshake(); handshake.ErrorMessage = errorText; } return(handshake); }