异常描述:
socket保持长连接,但当连接超过5秒钟后,服务器断开了连接,可是本地isClosed的值未变化,但closed的值改变了(可惜不能用)。这让我感到莫名其妙。麻烦哪位大侠来解释一下,我相信许多人都未碰到过。下面是我写的连接IOS推送服务器的代码
SSLContext sslc;   
KeyManagerFactory kmf = KeyManagerFactory.getInstance(ALGORITHM);   
KeyStore keystore = KeyStore.getInstance(KEYSTORE_TYPE_PKCS12);   
keystore.load(new BufferedInputStream(new FileInputStream(new File(KEY_STORE))),PASSWORD.toCharArray());   
 kmf.init(keystore, PASSWORD.toCharArray());   
sslc = SSLContext.getInstance("TLS");   
sslc.init(kmf.getKeyManagers(), null, new SecureRandom());   
ssf = sslc.getSocketFactory();
s = (SSLSocket) ssf.createSocket("gateway.sandbox.push.apple.com", 2195);
Java socketjavasocket

解决方案 »

  1.   

    public boolean isClosed()
    Returns the closed state of the socket. Returns:
    true if the socket has been closed
    public void close()
               throws IOException
    Closes this socket. 
    Any thread currently blocked in an I/O operation upon this socket will throw a SocketException. Once a socket has been closed, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created. Closing this socket will also close the socket's InputStream and OutputStream. If this socket has an associated channel then the channel is closed as well. 
    Specified by:
    close in interface Closeable 
    Throws: 
    IOException - if an I/O error occurs when closing this socket.
      

  2.   

    closed是Socket的一个属性,不是指close();
      

  3.   

    文档我也看了,可是没有介绍closed与isClosed()之间有什么联系,isClosed()能否用来判断一个连接是否断开