/// <summary> /// WebSocket implementation OnBinary event handler. /// </summary> private void OnBinary(WebSocket ws, byte[] data) { if (ws != Implementation) { return; } if (HTTPManager.Logger.Level <= BestHTTP.Logger.Loglevels.All) { HTTPManager.Logger.Verbose("WebSocketTransport", "OnBinary", this.Manager.Context); } IncomingPacket packet = IncomingPacket.Empty; try { packet = this.Manager.Parser.Parse(this.Manager, new BufferSegment(data, 0, data.Length)); } catch (Exception ex) { HTTPManager.Logger.Exception("WebSocketTransport", "OnBinary Packet parsing", ex, this.Manager.Context); } if (!packet.Equals(IncomingPacket.Empty)) { try { OnPacket(packet); } catch (Exception ex) { HTTPManager.Logger.Exception("WebSocketTransport", "OnBinary OnPacket", ex, this.Manager.Context); } } }
public void Call(IncomingPacket packet) { if (packet.Equals(IncomingPacket.Empty)) { return; } string name = packet.EventName; object[] args = packet.DecodedArg != null ? new object[] { packet.DecodedArg } : packet.DecodedArgs; Call(name, args); }
/// <summary> /// WebSocket implementation OnMessage event handler. /// </summary> private void OnMessage(WebSocket ws, string message) { if (ws != Implementation) { return; } if (HTTPManager.Logger.Level <= BestHTTP.Logger.Loglevels.All) { HTTPManager.Logger.Verbose("WebSocketTransport", "OnMessage: " + message, this.Manager.Context); } IncomingPacket packet = IncomingPacket.Empty; try { packet = this.Manager.Parser.Parse(this.Manager, message); if (packet.TransportEvent == TransportEventTypes.Open) { packet.DecodedArg = BestHTTP.JSON.LitJson.JsonMapper.ToObject <HandshakeData>(packet.DecodedArg as string); } } catch (Exception ex) { HTTPManager.Logger.Exception("WebSocketTransport", "OnMessage Packet parsing", ex, this.Manager.Context); } if (!packet.Equals(IncomingPacket.Empty)) { try { OnPacket(packet); } catch (Exception ex) { HTTPManager.Logger.Exception("WebSocketTransport", "OnMessage OnPacket", ex, this.Manager.Context); } } }