简体   繁体   English

重置WebSocket

[英]Resetting websocket

I'm writing program that communicates through web sockets and sends serialized objects. 我正在编写通过Web套接字进行通信并发送序列化对象的程序。 I have problem in situation, when connection between server and client is lost. 服务器和客户端之间的连接丢失时,我遇到了问题。 I get this exception: 我得到这个例外:

java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1877)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1786)
at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1286)
at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1231)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1427)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1577)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:351)
at common.WebSocketServer.sendResponse(WebSocketServer.java:103)
at common.WebSocketServer.listen(WebSocketServer.java:86)
at common.WebSocketServer.main(WebSocketServer.java:50)

When I use method socket.isConnected() to check, if server should abandon this client, it returns true (why?), even after closing socket and opening again it is still opened. 当我使用方法socket.isConnected()进行检查时,服务器是否应该放弃此客户端,即使关闭套接字并再次打开后,它仍会返回true(为什么?)。 What should I do? 我该怎么办?

There are several possible causes but the most common are that you had written to a connection that had already been closed by the peer, or that the peer closed the connection while it still had pending data to read. 有多种可能的原因,但最常见的原因是您已写入已被对等方关闭的连接,或者对等方在仍有待读取数据时关闭了该连接。 Both being application protocol errors. 两者都是应用程序协议错误。

Socket.isConnected() tells you about the state of the socket. Socket.isConnected()告诉您套接字的状态。 Not of the connection. 没有连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM