public static void main(String[] args)
{
InetAddress address = null;
Socket socket = null;
try
{
address = InetAddress.getByName( "202.102.15.115 ");
socket = new Socket(address, 8080);
if (socket.isConnected())
{
System.out.println( "ok! ");
}
else
{
System.out.println( "fail! ");
}
}
catch (Exception e)
{
e.printStackTrace();
System.out.println( "fail! ");
}
finally
{
if (null != socket)
{
try
{
socket.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
------解决方案--------------------
把你的catch里不写输出,不就不抛异常了?不过这样只是骗客户而已,断开连接必然出现提示,只是你捕获还是不捕获的问题