我扩展了 Socket 类并遇到了一些我不理解的错误,所以我寻求您的帮助。下面是一个简短的片段 - 没什么。如果我插入了错误的主机地址,它第一次给出的错误为operation time out
. 但是,随后当我尝试使用有效地址时,错误显示socket closed
。我没有明确关闭套接字并且 println 说socket closed is false
。知道为什么套接字关闭了吗?
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());