本帖最后由 张甲甲 于 2013-5-26 17:37 编辑
String str2 = new RecSocket(21000).recString; String str3 = new RecSocket(31000).recString; public class RecSocket extends DatagramSocket{ String recString; public RecSocket(int in)throws Exception{ DatagramSocket dSocket = new DatagramSocket(in); byte[] buf = new byte[1024]; DatagramPacket p = new DatagramPacket(buf,buf.length); dSocket.receive(p); buf = p.getData(); dSocket.close() }
String str2 = new RecSocket(21000).recString;
String str3 = new RecSocket(31000).recString;
主机1监听21000端口(主机2的返回值),31000(主机3返回的值)
java Socket编程中,为什么监听多个端口时出现有一个端口无法接受到信息,需要用到线程吗 |
|