Пример #1
0
        void OnNewClient(IAsyncResult _asyncResult)
        {
            System.Net.Sockets.Socket ClientSocket = ListenSocket.EndAccept(_asyncResult);
            ListenSocket.BeginAccept(OnNewClient, null);

            SetKeepAlive(ClientSocket, 1000 * 60, 1000);

            var NewClient = new TelnetClient {
                Socket = ClientSocket
            };

            if (Clients.ClientConnected(NewClient) == ClientAcceptanceStatus.Rejected)
            {
                NewClient.WasRejected = true;
                ClientSocket.Close();
            }
            else
            {
                // We will handle all the echoing echoing echoing
                //var echoCommand = new byte[]
                //{
                //    (byte)TelnetControlCodes.IAC,
                //    (byte)TelnetControlCodes.Will, // TODO: Handle client response denying this request
                //    (byte)TelnetControlCodes.Echo,
                //    (byte)TelnetControlCodes.IAC,
                //    (byte)TelnetControlCodes.Dont,
                //    (byte)TelnetControlCodes.Echo,
                //};
                //ClientSocket.Send(echoCommand);

                ClientSocket.BeginReceive(NewClient.Storage, 0, 1024, System.Net.Sockets.SocketFlags.Partial, OnData, NewClient);
                Console.WriteLine("New telnet client: " + ClientSocket.RemoteEndPoint.ToString());
            }
        }
Пример #2
0
        void OnNewClient(IAsyncResult _asyncResult)
        {
            System.Net.Sockets.Socket ClientSocket = ListenSocket.EndAccept(_asyncResult);
            ListenSocket.BeginAccept(OnNewClient, null);

            SetKeepAlive(ClientSocket, 1000 * 60, 1000);

            var NewClient = new TelnetClient { Socket = ClientSocket };
            if (Clients.ClientConnected(NewClient) == ClientAcceptanceStatus.Rejected)
            {
                NewClient.WasRejected = true;
                ClientSocket.Close();
            }
            else
            {
                // We will handle all the echoing echoing echoing
                //var echoCommand = new byte[]
                //{
                //    (byte)TelnetControlCodes.IAC,
                //    (byte)TelnetControlCodes.Will, // TODO: Handle client response denying this request
                //    (byte)TelnetControlCodes.Echo,
                //    (byte)TelnetControlCodes.IAC,
                //    (byte)TelnetControlCodes.Dont,
                //    (byte)TelnetControlCodes.Echo,
                //};
                //ClientSocket.Send(echoCommand);

                ClientSocket.BeginReceive(NewClient.Storage, 0, 1024, System.Net.Sockets.SocketFlags.Partial, OnData, NewClient);
                Console.WriteLine("New telnet client: " + ClientSocket.RemoteEndPoint.ToString());
            }
        }