import java.net.*;
class UdpSend3
{
public static void main(String[] args) throws Exception
{
DatagramSocket ds=new DatagramSocket();
byte[] buf="java is coming back".getBytes();
DatagramPacket dp=new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.0.6"),10009);
ds.send(dp);
ds.close();
}
}
class UdpRece3
{
public static void main(String[] args) throws Exception
{
DatagramSocket ds=new DatagramSocket(10009);
byte[] buf=new byte[1024];
DatagramPacket dp=new DatagramPacket(buf,buf.length);
ds.receive(dp);
String ip=dp.getAddress().getHostAddress();
String data=new String(dp.getData(),0,dp.getLength());
int port =dp.getPort();
System.out.println(ip+":"+data+":"+port);
}
ds.close();
}
为什么老是提示这样的错误啊,很费解!!!!!!!!{:soso_e118:}
|
|