简单Socket-Udp通信
在本文中涉及到通信,仅做简单的通信(服务端接受消息,由客户端发出消息)
如有需要,根据需求可直接copy使用
关键字Socket
需要引用命名空间:
using System.Net;
using System.Net.Sockets;
服务端:
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace Socket_UdpServer
{
class Program
{
static void Main(string[] args)
{
SocketStart(); //开启Udp通信
Console.Read();
}
/// <summary>
/// Udp通信服务端
/// </summary>
private static void SocketStart()
{
Socket udpServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); //声明Udp通信
int localPort = 8765;
IPAddress localIP = IPAddress.Parse("192.168.11.83");
EndPo