示例#1
0
 private void OnFrameRecived(HttpWebSocketFrame frame)
 {
     try
     {
         FrameRecivedHandler handler;
         if (null != (handler = (FrameRecivedHandler)this.frameRecived))
         {
             handler(frame);
         }
     }
     catch
     {
         this.Open = false;
         Thread.Sleep(100);
     }
 }
示例#2
0
        public void ReadNewData()
        {
            // Read and parse request
            var buffer = new byte[0] {
            };

            // TODO: add request timeout
            while (!this.request.RequestError)
            {
                try
                {
                    byte[] incomingPacket = this.request.ReadIncomingPacket(stream, socket);
                    buffer = CombineByteArrays(buffer, incomingPacket);

                    if (buffer.Length > 0 && incomingPacket.Length == 0)
                    {
                        OnFrameRecived(HttpWebSocketFrame.DecodeFrame(buffer));
                        break;
                    }
                    else
                    if (incomingPacket.Length != 0)
                    {
                        // wait until entire request is recived
                        Thread.Sleep(1);
                    }

                    Thread.Sleep(1);
                }
                catch
                {
                    this.Open = false;
                    return;
                }
            }

            NewData(JsonHelper.BytesToJson(HttpWebSocketFrame.DecodeFrame(buffer).Payload));
        }
示例#3
0
 public void SendString(string message)
 {
     Send(HttpWebSocketFrame.EncodeFrame(message).EncodedFrame);
 }