我擴展了Socket類並運行了一些我不明白的錯誤,所以我尋求你的幫助。下面是一個簡短的片段 - 沒什麼。如果我插入了錯誤的主機地址,它第一次給出錯誤信息operation time out
。但是,當我嘗試使用有效地址的後續時間,錯誤說socket closed
。我沒有明確關閉套接字,並且println說socket closed is false
。任何想法爲什麼套接字關閉?java套接字SocketException套接字關閉
java.net.SocketException: Socket closed
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at edu.astar.i2r.ppdf.exchange.p2p.PeerClient.connect(PeerClient.java:251)
at edu.astar.i2r.ppdf.exchange.p2p.PeerClient.connectToServer(PeerClient.java:89)
at edu.astar.i2r.ppdf.demo.ui.client.peertopeer.P2PParamsPage$1.actionPerformed(P2PParamsPage.java:87)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
@Override
public void connect(SocketAddress endPoint) throws IOException{
System.out.println("socket closed is " + this.isClosed());
super.connect(endPoint);
logger.info("Connected to server...");
this.ostream = new ObjectOutputStream(this.getOutputStream());
this.istream = new ObjectInputStream(this.getInputStream());