connection timed out: connection
请教一个问题:
我做了个探测局域网用户的程序,对方能收到我的udp广播数据报,但用tcp连接总是会超时是什么原因呢·?
class detector extends Thread //主动探测主机信息发送端
{
String userIp;
public detector(String userIp)
{
this.userIp=userIp;
}
public void run()
{
try
{
System.out.println( "start to connect "+userIp+ " ...... "); //可以运行到这里
Socket s = new Socket(InetAddress.getByName(userIp),5001);
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
os.write(InetAddress.getLocalHost().getHostName().getBytes());//写入用户名
os.write(System.getProperty( "user.name ").getBytes()); //写入登录名
os.write(InetAddress.getLocalHost().toString().getBytes()); //写入ip地址
String userName,loginName,userIp;
byte[] buf=new byte[100];
int len=is.read(buf);
if(len!=-1)
{
userName=new String(buf,0,len);
len=is.read(buf);
if(len!=-1)
{
loginName=new String(buf,0,len);
len=is.read(buf);
if(len!=-1)
{
userIp=new String(buf,0,len);
al.add(new user(userName,loginName,userIp));
tableInit();
}
}
}
is.close();
os.close();