日期:2014-05-17 浏览次数:21072 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace SocketUDPClient2
{
class Program
{
public class Client_Th
{
static void Main(string[] args)throws IOException
{
DatagramSocket socket=new DatagramSocket();//创建套接字
byte buf[]=new Byte [256];
InetAddress=InetAddress.getByName("192.168.1.108");//服务器IP
DatagramPacket packet=new DatagramPacket(buf,buf,Length,address,2000);//创建要发送的数据报对象
socket.send(packet);//发送数据报
packet=new DatagramPacket(buf,buf,length);//创建要接收的数据包对象
socket.receive(packet);//接收数据报
String receive=new String(packet getData());
System.out.println("The string receive from server:"+receive);
Socket.close();
}
}
}
}