Example #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);
        }
Example #2
0
        internal SocketIOSocket(EngineIOSocket Socket, SocketIOServer Server)
        {
            AckManager.SetTimeout(Server.Option.PingTimeout);

            Socket.OnMessage(OnPacket);
            Socket.OnClose((message, description) => OnDisconnect(description));

            this.Server = Server;
            this.Socket = Socket;
        }
Example #3
0
        private void OnConnection(EngineIOSocket EngineIOSocket)
        {
            SocketIOSocket Socket = new SocketIOSocket(EngineIOSocket, this);

            SimpleMutex.Lock(ClientMutex, () =>
            {
                _Clients.Add(Socket);

                Socket.On(SocketIOEvent.DISCONNECT, () =>
                {
                    SimpleMutex.Lock(ClientMutex, () =>
                    {
                        _Clients.Remove(Socket);
                    });
                });

                Socket.Emit(SocketIOPacket.CreateConnectionPacket());
                ConnectionHandlerManager.Emit(SocketIOEvent.CONNECTION, Socket);
            });
        }