s.setSoTimeout(long time)就是要等待time的时间长,如果没有连接上就自动放弃连接
s.isClose()和s.isConnect()用来判断是否连接上啊
有时候你需要在某些条件下判断Socket的状态就用得上了

解决方案 »

  1.   

    Socket s=new Socket("192.168.0.1",8888);
       Creates a stream socket and connects it to the specified port number at the specified IP address. s.setSoTimeout(long);
       Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.boolean  isClosed()  Returns the closed state of the socket.boolean isConnected()  Returns the connection state of the socket.
      

  2.   

    感谢上面两位同!但还没有告诉我:s.isClose()和s.isConnect()有什么区别啊!我也知道它们都是SOCKET的状态!但这个状态我不感兴趣!
      

  3.   

    简单理解就象拨号上网,线路通,就是网线都是好的,就是Connection. 如果没拨号连上网络,就是close。
      

  4.   

    s.setSoTimeout(long); 设置服务器等待连接的时间  如果超出这个时间还没有客户进行连接则会生产一个异常
    s.isClose()
    通信结束  要断开连接 因为如果客户通信结束,而服务器当然也要与其断开连接
    isConnect() 
    接通 可以通信