循环呗 java.net.Socket sock;
String host="localhost";
int port=70;
try{
java.net.InetAddress.getByName(host);
}catch(UnknownHostException ue){
ue.printStackTrace();
return ;
}
while(true){
try{
sock=new Socket(host,port);
System.out.println("the port:"+port+" is ok ");
break;
}catch(IOException ioe){
System.out.println("not exists port:"+port);
port++;
if (port>=5000)
break;
}catch(SecurityException se){
se.printStackTrace();
break;
}
}
String host="localhost";
int port=70;
try{
java.net.InetAddress.getByName(host);
}catch(UnknownHostException ue){
ue.printStackTrace();
return ;
}
while(true){
try{
sock=new Socket(host,port);
System.out.println("the port:"+port+" is ok ");
break;
}catch(IOException ioe){
System.out.println("not exists port:"+port);
port++;
if (port>=5000)
break;
}catch(SecurityException se){
se.printStackTrace();
break;
}
}
解决方案 »
- 我想了很久,总觉得Java1.5等版本,这样做不当。
- 谁来说说java 在什么情况下内存泄露?
- 请教一个关于import的问题
- 如何用java设置系统时间
- JDBC操作MS SQL数据库更新数据,如果有触发器,则stmt.executeUpdate(strSql)无法正确返回受影响的行数,怎么办?
- 疯掉了,我的程序界面怎么自己不刷新了?
- 怎么判断一个字符是否在一个字符串中存在?
- 多态问题
- 为什么 经常执行应用程序或者 applet开始form无任何显示,要最大化窗口才有 (如果把html文件 applet 尺寸改小就没事)
- 为什么我将TestArea设为只读后,滚动条就不能动了。
- 如何解决JDBC-ODBC连接SQL Server取中文值为乱码?
- 关于显卡与编程的问题。
for example
telnet 192.168.0.1 8080
如果连接不上就是没有
如果有东西出来就是有