Esempio n. 1
0
 public void Decode(IClient client, Stream stream)
 {
     try
     {
         if (!OnWSConnected)
         {
             if (Response.Read(stream.ToPipeStream()))
             {
                 Completed?.Invoke(client, Response);
                 OnWSConnected = true;
             }
         }
         else
         {
             if (mReceiveFrame == null)
             {
                 mReceiveFrame = new AgentDataFrame();
             }
             if (mReceiveFrame.Read(stream.ToPipeStream()) == DataPacketLoadStep.Completed)
             {
                 Completed?.Invoke(client, mReceiveFrame);
                 mReceiveFrame = null;
             }
         }
     }
     catch (Exception e_)
     {
         throw new BXException("ws protocol decode error", e_);
     }
 }
Esempio n. 2
0
 protected virtual void OnReceiveMessage(AgentDataFrame message)
 {
     if (message.Type == DataPacketType.connectionClose)
     {
         Dispose();
         OnClientError(mNetClient, new ClientErrorArgs {
             Error = new BXException("ws connection close!"), Message = "ws connection close"
         });
         return;
     }
     if (message.Type == DataPacketType.ping || message.Type == DataPacketType.pong)
     {
         PingPongTime = DateTime.Now;
         if (message.Type == DataPacketType.ping)
         {
             AgentDataFrame pong = new AgentDataFrame();
             pong.Type = DataPacketType.pong;
             Send(pong);
         }
         return;
     }
     else
     {
         OnDataReceive(message);
     }
 }
Esempio n. 3
0
        public void Ping()
        {
            AgentDataFrame pong = new AgentDataFrame();

            pong.Type = DataPacketType.ping;
            Send(pong);
        }
Esempio n. 4
0
 protected virtual void OnDataReceive(AgentDataFrame data)
 {
     if (DataReceive != null)
     {
         WSReceiveArgs e = new WSReceiveArgs();
         e.Client = this;
         e.Frame  = data;
         DataReceive(this, e);
     }
 }
Esempio n. 5
0
        public virtual void Send(BeetleX.FastHttpApi.WebSockets.DataFrame frame)
        {
            AgentDataFrame agentDataFrame = new AgentDataFrame();

            if (frame.Body != null)
            {
                agentDataFrame.Body = (ArraySegment <byte>)frame.Body;
            }
            agentDataFrame.FIN  = frame.FIN;
            agentDataFrame.RSV1 = frame.RSV1;
            agentDataFrame.RSV2 = frame.RSV2;
            agentDataFrame.RSV3 = frame.RSV3;
            agentDataFrame.Type = frame.Type;
            WSClient.Send(agentDataFrame);
        }
Esempio n. 6
0
 protected virtual long GetTime(AgentDataFrame frame)
 {
     return(10);
 }
Esempio n. 7
0
 public void Send(AgentDataFrame data)
 {
     Connect();
     mNetClient.Send(data);
 }