Ejemplo n.º 1
0
        private void Handshake(string SID, EngineIOTransport Transport)
        {
            if (Option.SetCookie)
            {
                Transport.On(EngineIOTransport.Event.HEADERS, (Headers) =>
                {
                    List <string> Cookies = new List <string>();

                    foreach (string Key in Option.Cookies.Keys)
                    {
                        string Cookie = Key;
                        string Value  = Option.Cookies[Key];

                        if (!string.IsNullOrWhiteSpace(Value))
                        {
                            Cookie += ('=' + Value);
                        }

                        Cookies.Add(Cookie);
                    }

                    (Headers as NameValueCollection)["Set-Cookie"] = string.Join("; ", Cookies);
                });
            }

            EngineIOSocket Socket = new EngineIOSocket(SID, this, Transport);

            _Clients.TryAdd(SID, Socket.Once(EngineIOSocket.Event.CLOSE, () => _Clients.TryRemove(SID, out _)));

            Emit(Event.CONNECTION, Socket);
        }
Ejemplo n.º 2
0
        private void SetTransport(EngineIOTransport Transport)
        {
            if (this.Transport != null)
            {
                this.Transport.Off();
            }

            this.Transport = Transport
                             .On(EngineIOTransport.Event.DRAIN, OnDrain)
                             .On(EngineIOTransport.Event.PACKET, (Packet) => OnPacket(Packet as EngineIOPacket))
                             .On(EngineIOTransport.Event.ERROR, (Exception) => OnError(Exception as Exception))
                             .On(EngineIOTransport.Event.CLOSE, () => OnClose("Transport close."))
                             .Open();
        }
Ejemplo n.º 3
0
        private void SetTransport(EngineIOTransport Transport)
        {
            this.Transport = Transport
                             .On(EngineIOTransport.Event.DRAIN, Flush)
                             .On(EngineIOTransport.Event.DRAIN, OnDrain)
                             .On(EngineIOTransport.Event.PACKET, (Packet) => OnPacket(Packet as EngineIOPacket))
                             .Once(EngineIOTransport.Event.ERROR, (Exception) => OnError(Exception as Exception))
                             .Once(EngineIOTransport.Event.CLOSE, (Argument) =>
            {
                object[] Temp = Argument as object[];

                if (Temp != null)
                {
                    OnClose(Temp[0] as string, Temp[1] as Exception);
                }
                else
                {
                    OnClose("Transport closed");
                }
            });

            Cleanup.Enqueue(() => this.Transport.Off());
        }