using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//发送数据
Client("42.121.105.222", 10086, "mzwu.com");
}
///
/// 客户端
///
///
///
///
static void Client(string ip, int port, string message)
{
try
{
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPEndPoint ipendpoint = new IPEndPoint(IPAddress.Parse(ip), port);
byte[] data = Encoding.Default.GetBytes(message);
socket.SendTo(data, ipendpoint);
socket.Close();
}
catch (Exception ex)
{
Console.WriteLine("{0:HH:mm:ss}->{1}", DateTime.Now, ex.Message);
Console.ReadKey();
}
}
}
}
|