Esempio n. 1
0
        private void CollectSocket(Socket socket)
        {
            ISocket isocket = new TcpSocket(socket, RandomId.Generate());

            while (!csockets.TryAdd(isocket.Id, isocket))
            {
                isocket = new TcpSocket(socket, RandomId.Generate());
            }
            isocket.OnSocketDisconnected += RemoveSocket;
            SendServerToken(isocket);
            OnConnectionRequested?.Invoke(isocket);
        }
Esempio n. 2
0
        private bool CollectSocket(IPEndPoint endPoint, out UdpSocket isocket)
        {
            Socket socket = Setup(_localEndpoint);

            isocket = new UdpSocket(socket, endPoint, RandomId.Generate());
            while (!csockets.TryAdd(isocket.Id, isocket))
            {
                isocket = new UdpSocket(socket, endPoint, RandomId.Generate());
            }
            isocket.OnSocketDisconnected += RemoveSocket;
            isocket.Connected             = true;
            try
            {
                SendServerToken(isocket);
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }