public IClientPacket Clone() { WSPacket result = new WSPacket(); result.WSClient = this.WSClient; return(result); }
private void Connect() { if (IsConnected) { return; } lock (mLockConnect) { if (IsConnected) { return; } mWScompletionSource = new TaskCompletionSource <bool>(); if (mNetClient == null) { string protocol = UriHost.Scheme.ToLower(); if (!(protocol == "ws" || protocol == "wss")) { OnConnectResponse(new BXException("protocol error! host must [ws|wss]//host:port"), null); mWScompletionSource.Task.Wait(); } WSPacket wSPacket = new WSPacket { WSClient = this }; if (UriHost.Scheme.ToLower() == "wss") { mNetClient = SocketFactory.CreateSslClient <AsyncTcpClient>(wSPacket, UriHost.Host, UriHost.Port, SSLAuthenticateName); } else { mNetClient = SocketFactory.CreateClient <AsyncTcpClient>(wSPacket, UriHost.Host, UriHost.Port); } mNetClient.LittleEndian = false; mNetClient.PacketReceive = OnPacketCompleted; mNetClient.ClientError = OnClientError; } mDataFrames = new System.Collections.Concurrent.ConcurrentQueue <AgentDataFrame>(); bool isnew; if (mNetClient.Connect(out isnew)) { OnWriteConnect(); } else { OnConnectResponse(mNetClient.LastError, null); } mWScompletionSource.Task.Wait(); } }