using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net.Sockets;
using System.Net;
namespace MyUdpClient
{
class Program
{
static void Main(string[] args)
{
UdpClient client = new UdpClient(new IPEndPoint(IPAddress.Parse("192.168.1.113"), 7788));
IPEndPoint remoteIPEndPoint = new IPEndPoint(IPAddress.Any, 0);
byte[] data = client.Receive(ref remoteIPEndPoint);
string msg = Encoding.UTF8.GetString(data);
Console.WriteLine(msg);
client.Close();
Console.ReadLine();
}
}
}
(二)客户端
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
namespace MyUdpClient2
{
class Program
{
static void Main(string[] args)
{
UdpClient client = new UdpClient();
string message = "UDPClient客户端";
byte[] data = Encoding.UTF8.GetBytes(message);
client.Send(data,data.Length,new IPEndPoint(IPAddress.Parse("192.168.1.113"),7788));
client.Close();
Console.ReadKey();
}
}
}
文章目录(一)服务器(二)客户端(一)服务器using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Net.Sockets;using System.Net;namespace MyUdpClient{ class Program { static void Ma