private void OnWebSocketMessage(object sender, MessageEventArgs e) { if (e.IsText || e.IsBinary) { EngineIOPacket Packet; if (e.IsText) { Packet = EngineIOPacket.Decode(e.Data); } else { Packet = EngineIOPacket.Decode(e.RawData); } if (Packet.Type != EngineIOPacketType.CLOSE) { OnPacket(Packet); if (Packet.Type == EngineIOPacketType.OPEN) { Writable = true; } } else { Close(); } } }
private void OnWebSocketMessage(object sender, MessageEventArgs e) { NameValueCollection Headers = new NameValueCollection(); Emit(Event.HEADERS, Headers); if (Headers.Count > 0) { Dictionary <string, string> CustomHeaders = new Dictionary <string, string>(); foreach (string Key in Headers.AllKeys) { CustomHeaders[Key] = Headers[Key]; } Client.CustomHeaders = CustomHeaders; } EngineIOPacket Packet = EngineIOPacket.Decode(e); if (Packet.Type != EngineIOPacketType.CLOSE) { OnPacket(Packet); } else { Close(); } }
private void HandleResponse(EngineIOHttpMethod Method, HttpWebResponse Response) { using (Response) { if (Response.StatusCode == HttpStatusCode.OK) { if (Option.WithCredentials) { Cookies.Add(Response.Cookies); } if (Method == EngineIOHttpMethod.GET) { EngineIOPacket[] Packets = EngineIOPacket.Decode(Response); if ((Packets?.Length ?? 0) > 0) { foreach (EngineIOPacket Packet in Packets) { if (Packet.Type != EngineIOPacketType.CLOSE) { if (ReadyState == EngineIOReadyState.OPENING) { OnOpen(); } OnPacket(Packet); if (Packet.Type == EngineIOPacketType.OPEN) { Writable = true; } } else { OnClose(); } } if (ReadyState != EngineIOReadyState.CLOSED) { Polling = false; Emit(Event.POLL_COMPLETE); if (ReadyState == EngineIOReadyState.OPEN) { ThreadPool.QueueUserWorkItem((_) => Poll()); } } } } else if (Method == EngineIOHttpMethod.POST) { Writable = true; Emit(Event.DRAIN); } } } }
private void OnDataRequest(HttpListenerRequest Request, HttpListenerResponse Response) { using (Response) { try { if (DataRequest == null) { EngineIOPacket[] Packets = EngineIOPacket.Decode(Request); Response.Headers = SetHeaders(Response.Headers); using (Response.OutputStream) { Response.KeepAlive = false; Response.ContentType = "text/html"; Response.ContentEncoding = Encoding.UTF8; Response.ContentLength64 = 2; Response.OutputStream.Write(Encoding.UTF8.GetBytes("ok"), 0, 2); } foreach (EngineIOPacket Packet in Packets) { if (Packet.Type != EngineIOPacketType.CLOSE) { OnPacket(Packet); } else { OnClose(); } } CleanupDataRequest(); } else { throw new EngineIOException("Data request overlap from client"); } } catch (Exception Exception) { CloseResponse(Response); OnDataRequestClose(Exception); } } }