mytcpclient.cs

来自「Csharp网络应用案例导航 Csharp网络应用案例导航」· CS 代码 · 共 33 行

CS
33
字号
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 + =
减小字号Ctrl + -
显示快捷键?