public static CLHandshake LoadFromString(string value) { CLHandshake returnItem = new CLHandshake(); if (!string.IsNullOrEmpty(value)) { string[] items = value.Split(new char[] { ':' }); if (items.Count() == 4) { int hb = 0; int ct = 0; returnItem.SID = items[0]; if (int.TryParse(items[1], out hb)) { int pct = (int)(hb * .75); // setup client time to occure 25% faster than needed returnItem.HeartbeatTimeout = pct; } if (int.TryParse(items[2], out ct)) { returnItem.ConnectionTimeout = ct; } returnItem.Transports.AddRange(items[3].Split(new char[] { ',' })); return(returnItem); } } return(null); }
private CLHandshake RequestHandshake(Uri uri) { string value = string.Empty; string errorText = string.Empty; CLHandshake handshake = null; using (WebClient client = new WebClient()) { value = client.DownloadString(string.Format("{0}://{1}:{2}/socket.io/1/{3}", uri.Scheme, uri.Host, uri.Port, uri.Query)); if (string.IsNullOrEmpty(value)) { errorText = "Did not receive handshake string from server"; } } if (string.IsNullOrEmpty(errorText)) { handshake = CLHandshake.LoadFromString(value); } else { handshake = new CLHandshake(); handshake.ErrorMessage = errorText; } return(handshake); }