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

📄 class1.cs

📁 Professional C# 2nd Edition
💻 CS
字号:
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace Wrox.ProCSharp.InternetAccess.UdpExample
{
    
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
			UdpClient udpClient = new UdpClient();

			string sendMsg = "Hello Echo Server";
			byte [] sendBytes = Encoding.ASCII.GetBytes(sendMsg);

			udpClient.Send(sendBytes, sendBytes.Length, "localhost", 7);

			IPEndPoint endPoint = new IPEndPoint(0,0);
			byte [] rcvBytes = udpClient.Receive(ref endPoint);
			string rcvMessage = Encoding.ASCII.GetString(rcvBytes, 0, rcvBytes.Length);

			// should print out "Hello Echo Server"
			Console.WriteLine(rcvMessage);
			Console.ReadLine();
		}
	}
}

⌨️ 快捷键说明

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