import java.net.*;public class TestUDPServer {
public static void main(String[] args) throws Exception{
byte buf[] = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
DatagramSocket ds = new DatagramSocket(5678);
while(true)
{
ds.receive(dp);
System.out.println(new String(buf,0,dp.getLength()));
}
}
}import java.net.*;
import java.io.*;public class TestUDPClient {
public static void main(String[] args) throws Exception {
byte[] buf = (new String("Hello")).getBytes();
DatagramPacket dp = new DatagramPacket(buf, buf.length,
new InetSocketAddress("127.0.0.1", 5678)
);
DatagramSocket ds = new DatagramSocket(9999);
ds.send(dp);
ds.close();
}
}为什么这两段代码连不上呢。
我发给别人试过了。别人都可以的。我为什么的不行啊。
请高手指教。
public static void main(String[] args) throws Exception{
byte buf[] = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf, buf.length);
DatagramSocket ds = new DatagramSocket(5678);
while(true)
{
ds.receive(dp);
System.out.println(new String(buf,0,dp.getLength()));
}
}
}import java.net.*;
import java.io.*;public class TestUDPClient {
public static void main(String[] args) throws Exception {
byte[] buf = (new String("Hello")).getBytes();
DatagramPacket dp = new DatagramPacket(buf, buf.length,
new InetSocketAddress("127.0.0.1", 5678)
);
DatagramSocket ds = new DatagramSocket(9999);
ds.send(dp);
ds.close();
}
}为什么这两段代码连不上呢。
我发给别人试过了。别人都可以的。我为什么的不行啊。
请高手指教。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货