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

📄 mytcpclient.cs

📁 Csharp网络应用案例导航 Csharp网络应用案例导航
💻 CS
字号:
using System; 
using System.Net.Sockets; 
using System.Text; 

namespace HelloWorld
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class MyTcpClient
	{
		private const int portNum = 9999;   
		private const string hostName = "166.111.147.25";   
		public static int Main(String[] args) 
		{ 
			try 
			{ 
				TcpClient client = new TcpClient(hostName, portNum); 
				NetworkStream ns = client.GetStream(); 
				byte[] bytes = new byte[1024]; 
				int bytesRead = ns.Read(bytes, 0, bytes.Length); 
				Console.WriteLine(Encoding.ASCII.GetString(bytes,0,bytesRead)); 
				client.Close(); 
				Console.ReadLine();
			} 
			catch (Exception e) 
			{ 
				Console.WriteLine(e.ToString()); 
			} 
			return 0; 
		} 
	}
}

⌨️ 快捷键说明

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