import java.net.*;
import java.io.*;
class L
{
public static void main(String args[]) throws Exception
{
DatagramSocket ds=new DatagramSocket();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line=null;
while((line=br.readLine())!=null)
{
byte[] buf=new byte[1024];
DatagramPacket dp=new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.0.255"),20006);
ds.send(dp);
}
ds.close();
}
}
class L1
{
public static void main(String args[]) throws Exception
{
DatagramSocket ds=new DatagramSocket(20006);
while(true)
{
byte[] buf=new byte[1024];
DatagramPacket dp=new DatagramPacket(buf,buf.length);
ds.receive(dp);
String text=new String(dp.getData(),0,dp.getLength());
System.out.println(text);
}
}
}
网络编程 发送与接收 (第一次失败)
最新推荐文章于 2024-05-20 22:34:39 发布