/// <summary> /// wsUrl:ws://ip:port /// </summary> /// <param name="wsUrl"></param> /// <returns></returns> public bool Connect(string wsUrl) { Random rand = new Random(DateTime.Now.Millisecond); WSConnectionItem wsItem = new WSConnectionItem(wsUrl); bool isOk = _token.ConnectTo(wsItem.port, wsItem.domain); if (isOk == false) { throw new Exception("连接失败..."); } string req = new AccessInfo() { host = wsItem.host, origin = "http://" + wsItem.host, secWebSocketKey = Convert.ToBase64String(_encoding.GetBytes(wsUrl + rand.Next(100, 100000).ToString())) }.ToString(); isOk = _token.SendAsync(new BufferSegment(_encoding.GetBytes(req))); _resetEvent.WaitOne(_waitingTimeout); return(IsConnected); }
public bool Connect(WSConnectionItem wsUrl) { return(Connect(wsUrl)); }