如果我的套接字已连接但未关闭,为什么我要发送 RST? [英] Why am I sending an RST if my socket is connected and not closed?

查看:34
本文介绍了如果我的套接字已连接但未关闭,为什么我要发送 RST?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Android 设备,它使用 java.net.Socket 与 PC 进行无线通信.一切都很好,但如果我在整整 1 分钟内什么都不做(即不使用网络),那么当 Android 向 PC 发送一个数据包时,PC 会收到它并发送一个 ACK​​,但 Android 会以 RST 进行响应.

I have an Android device that communicates wirelessly with a PC, using a java.net.Socket. Everything hums along fine, but if I do nothing (i.e., no network use) for exactly 1 minute then when the Android sends a packet of data to the PC the PC receives it and sends an ACK, but the Android responds with an RST.

来自 Wireshark(10.1.2.1 是 Android,10.1.2.11 是 PC)...

From Wireshark ( 10.1.2.1 is the Android, 10.1.2.11 is the PC)...

356 0.112470 10.1.2.1 10.1.2.11 TCP 97 34360→181 [PSH, ACK] Seq=1Ack=1 Win=4935 Len=31 TSval=156103571 TSecr=320673352

356 0.112470 10.1.2.1 10.1.2.11 TCP 97 34360→181 [PSH, ACK] Seq=1 Ack=1 Win=4935 Len=31 TSval=156103571 TSecr=320673352

359 0.000011 10.1.2.11 10.1.2.1 TCP 66 181→34360 [ACK] Seq=1 Ack=32赢=260 Len=0 TSval=320738236 TSecr=156103571

359 0.000011 10.1.2.11 10.1.2.1 TCP 66 181→34360 [ACK] Seq=1 Ack=32 Win=260 Len=0 TSval=320738236 TSecr=156103571

360 0.000304 10.1.2.1 10.1.2.11 TCP 60 34360→181 [RST] Seq=32 Win=0长度=0

360 0.000304 10.1.2.1 10.1.2.11 TCP 60 34360→181 [RST] Seq=32 Win=0 Len=0

此时,如果我询问套接字的成员变量,它会显示 ...

At this point if I interrogate the socket's member variables it says . . .

  • isConnected = 真
  • isCreated = true
  • isInputShutdown = false
  • isOutputShutdown = false
  • isClosed = false
  • isBound = 真

...看起来我应该仍然可以正常接收数据包.那么我如何弄清楚我为什么要发送 RST?

... which looks like I should still be receiving packets just fine. So how do I figure out why I'm sending RST?

注意 - 没有设置可以睡眠"或关闭 wifi 或显示器或在此设备上启用的任何其他省电功能设置.

N.B. - there are no settings to "sleep" or turn off the wifi or display or any other battery-saving features set enabled on this device.

推荐答案

1 分钟的延迟看起来像是超时.它可能是 SO_TIMEOUT 但这不会在其自身上生成网络活动.此外,发送的最后一个数据包包含 31 个字节的数据这一事实似乎表明涉及应用程序.一种可能的情况是:

The 1 minute delay looks like a timeout. It may be the SO_TIMEOUT but this does not generate network activity on itself. Also the fact that the last packet sent contains 31 bytes of data seems to indicate that the application is involved. A possible scenario would be :

  • Android 应用程序超时(自行或由套接字的SO_TIMEOUT 触发)
  • 它发送最后一块数据,例如通过刷新输出流.
  • 它会突然关闭套接字,例如使用 setSoLinger(true, 0) 套接字选项.
  • The android application times out (on its own or triggered by a socket's SO_TIMEOUT)
  • It sends a last chunk of data, e.g. by flushing an output stream.
  • It closes abruptly the socket, for example by using the setSoLinger(true, 0) socket option.

这篇关于如果我的套接字已连接但未关闭,为什么我要发送 RST?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆