Java void sendUrgentData() 抛出 SocketException
我正在尝试使用 sendUrgentData() void 来确定连接是否仍然有效。通过此 void 发送的数据在服务器端将被忽略,但当连接丢失时,sendUrgentData 在客户端会抛出 SocketException。
这就是应该如何进行。 然而,在多次调用 sendUrgentData 后,当连接仍然完全有效时,它似乎会断开连接并抛出 SocketException:
java.net.SocketException: Connection reset by peer: send
我用嗅探器检查了网络流量,发现重置数据包从未发送。 我应该如何解决这个问题?我试图避免以正常方式发送此数据,以避免损坏流中当前的数据。
I am trying to use the sendUrgentData() void to determine if a connection is still alive. The data send through this void will be ignored on the server side, but when a connection is lost, sendUrgentData throws a SocketException on the client side.
This is how is should go.
However, after calling sendUrgentData several times it seems to disconnect and throw the SocketException when the connection is still perfectly alive:
java.net.SocketException: Connection reset by peer: send
I checked the network traffic with a sniffer and found that the reset packet was never send.
How should I solve this? I'm trying to avoid sending this data the normal way to avoid corrupting the data currently in the stream.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
发送的数据不会被忽略,如果是用 Java 编写的,它将由服务器内联读取。所以你可能会导致协议错误。对等方重置连接意味着您已写入已被对等方关闭的连接......可能是为了响应协议错误。
The data sent won't be ignored, it will be read inline by the server, if it's written in Java. So you are probably causing a protocol error. Connection reset by peer means you have written to a connection that has already been closed by the peer ... probably in response to the protocol error.
如果底层实现不支持发送紧急数据,
Socket#sendUrgentData()
将抛出SocketException
。根据记忆,Java 1.6 上的套接字异常的消息描述类似于“不支持紧急数据”。您在什么平台上运行(Windows、Linux 等)?
您使用的 Java 版本是什么?
Socket#sendUrgentData()
will throw aSocketException
if the underlying implementation does not support sending of urgent data. From memory, the socket exception's message description on Java 1.6 is something like 'urgent data is not supported'.What platform are you running on (Windows, Linux, etc) ?
What version of Java are you using ?