对Socket设置Sotimeout参数,用Socket.setSotimeout(int i);
注意捕获InterruptedException 异常。
例如:socket1.setSotimeout(20000);//20seconds
ips=socket1.getInputstream();
dips=new DataInputstream(ips);  建议输入输出流放到send(),receive方法外面去定义byte[] r= new byte[1024];//定义一个接收缓冲字节数组同时修改你的receive()方法public byte[] receive() throws InterruptedException 
{
   try{
dips.read(r);}
catch(InterruptedException ie){ throw new InterruptedException("read out of time");}
}
使这个方法抛出InterruptedException在main()里可以起一个while(true){}
在try块里捕获InterruptedException,如果捕获到,就是读超时,在做相应处理