黑马程序员技术交流社区
标题:
网络编程问题:为啥这段代码只能执行一回第二次就没反应了!我在myeclipse中运行的!
[打印本页]
作者:
yang649981273
时间:
2014-8-19 23:57
标题:
网络编程问题:为啥这段代码只能执行一回第二次就没反应了!我在myeclipse中运行的!
//这是第一段
package com.Tcp2;
import java.net.*;
public class UdpRece2 {
public static void main(String[] args) throws Exception {
DatagramSocket ds=new DatagramSocket(10002);
while(true){
byte[] buf=new byte[1024];
DatagramPacket dp=new DatagramPacket(buf,buf.length);
ds.receive(dp);
String id=dp.getAddress().getHostAddress();
String data=new String(dp.getData(),0,dp.getLength());
System.out.println("IP"+id+"::::"+data);
}
}
}
复制代码
//这是第2段
package com.Tcp2;
import java.net.*;
import java.io.*;
public class Udpsend2 {
public static void main(String[] args)throws Exception{
DatagramSocket ds=new DatagramSocket(10002);
BufferedReader bis=new BufferedReader(new InputStreamReader(System.in));
String line=null;
while((line=bis.readLine())!=null){
if("886".equals(line))
break;
byte[] buf=line.getBytes();
DatagramPacket dp=
new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.1.113"),10002);
ds.send(dp);
}
ds.close();
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2