private void OnFrameRecived(HttpWebSocketFrame frame) { try { FrameRecivedHandler handler; if (null != (handler = (FrameRecivedHandler)this.frameRecived)) { handler(frame); } } catch { this.Open = false; Thread.Sleep(100); } }
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 = StringHelper.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)); }
public void SendString(string message) { Send(HttpWebSocketFrame.EncodeFrame(message).EncodedFrame); }