Пример #1
0
        public IClientPacket Clone()
        {
            WSPacket result = new WSPacket();

            result.WSClient = this.WSClient;
            return(result);
        }
Пример #2
0
 public void Connect()
 {
     if (IsConnected)
     {
         return;
     }
     lock (mLockConnect)
     {
         if (IsConnected)
         {
             return;
         }
         mWScompletionSource = new TaskCompletionSource <bool>();
         if (mNetClient == null)
         {
             string protocol = Host.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 (Host.Scheme.ToLower() == "wss")
             {
                 mNetClient = SocketFactory.CreateSslClient <AsyncTcpClient>(wSPacket, Host.Host, Host.Port, SSLAuthenticateName);
                 mNetClient.CertificateValidationCallback = CertificateValidationCallback;
             }
             else
             {
                 mNetClient = SocketFactory.CreateClient <AsyncTcpClient>(wSPacket, Host.Host, Host.Port);
             }
             mNetClient.LittleEndian  = false;
             mNetClient.PacketReceive = OnPacketCompleted;
             mNetClient.ClientError   = OnClientError;
         }
         mDataFrames = new System.Collections.Concurrent.ConcurrentQueue <object>();
         bool isNew;
         if (mNetClient.Connect(out isNew))
         {
             OnWriteConnect();
         }
         else
         {
             OnConnectResponse(mNetClient.LastError, null);
         }
         mWScompletionSource.Task.Wait(5000);
         if (!OnWSConnected)
         {
             throw new TimeoutException($"Connect {Host} websocket server timeout!");
         }
     }
 }