⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 telnetclient.txt

📁 Telnet Client源代码
💻 TXT
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace ConsoleApplication_Telnet
{
    class DateTimeClient
    {
        //声明变量dateTimeHost保存服务器主机IP
        private static IPEndPoint dateTimeHost;
        public static void Main(string[] args)
        {
            String hostIPString = args[0];
            String hostPortString = args[1];
            IPAddress hostIP = IPAddress.Parse(hostIPString);
            try
            {
                dateTimeHost =
                    new IPEndPoint(hostIP, Int32.Parse(hostPortString));
            }
            catch (ArgumentException e)
            {
                Console.WriteLine("Invalid port number!!");
                return;
            }
            Socket conn = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                conn.Connect(dateTimeHost);
            }
            catch (SocketException se)
            {
                Console.WriteLine("Could not extablish the connection!");
                return;
            }
            int bytes = 0;
            Byte[] RecvBytes = new Byte[256];
            String RecvString = "";
            bytes = conn.Receive(RecvBytes, RecvBytes.Length, 0);
            RecvString = Encoding.ASCII.GetString(RecvBytes, 0, bytes);
            Console.WriteLine(RecvString);
            conn.Shutdown(SocketShutdown.Both);
            conn.Close();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -