Exemple #1
0
        private void TcpSock_OnClientConnect(BaseServerSocket sender, Socket s)
        {
            InternalSecureSocketConnectedClient client = new InternalSecureSocketConnectedClient(s, _packager);

            client.SetId(_guidGenerator());
            client.BeginReceive(ReceiveHandler);
            client.Send(cl => {
                Clients.Add(cl);
                client.OnDisconnect += (c, err) => {
                    Clients.Remove(c);
                };

                OnClientConnect?.Invoke(this, cl);
            }, new HandshakePacket(true, client.Id));
        }
Exemple #2
0
        public SecureSocket StartServer(int port)
        {
            BaseServerSocket baseSock = new BaseServerSocket(Protocol);

            baseSock.OnClientConnect += TcpSock_OnClientConnect;

            if (!baseSock.BeginAccept(port))
            {
                return(null);
            }

            _openSockets.Add(baseSock);
            baseSock.OnClose += (s, err) => {
                _openSockets.Remove(s);
            };

            return(baseSock);
        }