/// <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 = clientProvider.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 = clientProvider.Send(new SegmentOffset(encoding.GetBytes(req))); resetEvent.WaitOne(waitingTimeout); return(IsConnected); }
public bool Connect(WSConnectionItem wsUrl) { return(Connect(wsUrl)); }