TCP Socket不接收数据,写入/发送不超时?

发布于 2024-10-04 09:33:21 字数 4023 浏览 9 评论 0原文

我已经使用 TCP 套接字制作了几个项目和模型,但这是我第一次遇到这种情况。

我在 Solaris Sparc 计算机上有一个 Linux 服务器应用程序,该应用程序应该接受来自 Web 服务器上的 OCX 的连接,但没有收到任何数据。我使用 netstat 来验证连接是否已建立。

我创建了一个小型 tcp 客户端来连接以充当 Web 服务器/ocx,但发生的情况是在写入时它停止在那里并且永远不会发生超时。即使我断开连接并等待几个小时,也没有任何反应。我什至使用setsockopt 来确保设置较低的超时值。另外,在另一端,没有收到数据,并且 select 语句在轮询 fd 集时超时。

有谁知道为什么写入或发送在写入套接字时不会超时?另外,有谁知道为什么在服务器上,未设置读取 fd 集?

这是来自 snoop 的转储:

solaris61 -> 10.1.0.37    TCP D=8882 S=35111 Fin Ack=1805515051 Seq=897643511 Len=0 Win=49640
10.1.0.37 -> solaris61    TCP D=35111 S=8882 Ack=897643512 Seq=1805515051 Len=0 Win=24818
solaris61 -> 10.1.0.37    TCP D=8882 S=35112 Syn Seq=921698308 Len=0 Win=49640 Options=<mss 1460,nop,wscale 0,nop,nop,sackOK>
10.1.0.37 -> solaris61    TCP D=35112 S=8882 Syn Ack=921698309 Seq=1829645518 Len=0 Win=24820 Options=<nop,wscale 0,nop,nop,sackOK,mss 1460>
solaris61 -> 10.1.0.37    TCP D=8882 S=35112 Ack=1829645519 Seq=921698309 Len=0 Win=49640
solaris61 -> 10.1.0.37    TCP D=8882 S=35112 Push Ack=1829645519 Seq=921698309 Len=2 Win=49640
10.1.0.37 -> solaris61    TCP D=35112 S=8882 Ack=921698311 Seq=1829645519 Len=0 Win=24818

使用“snoop -x0 -s1500”

solaris61 -> 10.1.0.37 TCP D=8882 S=35291 Syn Seq=4205016629 Len=0 Win=49640 选项=

   0: 0800 20f5 a3b5 000c 295d 6f44 0800 4500    .. .....)]oD..E.
  16: 0034 e4c7 4000 4006 0000 0a01 003d 0a01    .4..@.@......=..
  32: 0025 89db 22b2 faa3 7635 0000 0000 8002    .%.."...v5......
  48: c1e8 148a 0000 0204 05b4 0103 0300 0101    .è..............
  64: 0402                                       ..

10.1.0.37 -> Solaris61 TCP D=35291 S=8882 Syn Ack=4205016630 Seq=799808987 Len=0 Win=24820 Options=

   0: 000c 295d 6f44 0800 20f5 a3b5 0800 4500    ..)]oD.. .....E.
  16: 0034 c849 4000 4006 5e17 0a01 0025 0a01    .4.I@.@.^....%..
  32: 003d 22b2 89db 2fac 1ddb faa3 7636 8012    .=".../.....v6..
  48: 60f4 8ec1 0000 0103 0300 0101 0402 0204    `...............
  64: 05b4                                       ..

solaris61 -> 10.1.0.37 TCP D=8882 S=35291 Ack=799808988 Seq=4205016630 Len=0 Win=49640

   0: 0800 20f5 a3b5 000c 295d 6f44 0800 4500    .. .....)]oD..E.
  16: 0028 e4c8 4000 4006 0000 0a01 003d 0a01    .(..@.@......=..
  32: 0025 89db 22b2 faa3 7636 2fac 1ddc 5010    .%.."...v6/...P.
  48: c1e8 147e 0000                             .è.~..

Solaris61 -> 10.1.0.37 TCP D=8882 S=35291 Push Ack=799808988 Seq=4205016630 Len=2 Win=49640

   0: 0800 20f5 a3b5 000c 295d 6f44 0800 4500    .. .....)]oD..E.
  16: 002a e4c9 4000 4006 0000 0a01 003d 0a01    .*..@.@......=..
  32: 0025 89db 22b2 faa3 7636 2fac 1ddc 5018    .%.."...v6/...P.
  48: c1e8 1480 0000 750a                        .è....u.

10.1.0.37 -> Solaris61 TCP D=35291 S=8882 Ack=4205016632 Seq=799808988 Len=0 Win=24818

   0: 000c 295d 6f44 0800 20f5 a3b5 0800 4500    ..)]oD.. .....E.
  16: 0028 c84a 4000 4006 5e22 0a01 0025 0a01    .(.J@.@.^"...%..
  32: 003d 22b2 89db 2fac 1ddc faa3 7638 5010    .=".../.....v8P.
  48: 60f2 cf8c 0000 5555 5555 5555              `.....UUUUUU

Solaris61 -> 10.1.0.37 TCP D=8882 S=35291 Fin Ack=799808988 Seq=4205016632 Len=0 Win=49640

   0: 0800 20f5 a3b5 000c 295d 6f44 0800 4500    .. .....)]oD..E.
  16: 0028 e4ca 4000 4006 0000 0a01 003d 0a01    .(..@.@......=..
  32: 0025 89db 22b2 faa3 7638 2fac 1ddc 5011    .%.."...v8/...P.
  48: c1e8 147e 0000                             .è.~..

10.1.0.37 -> Solaris61 TCP D=35291 S=8882 Ack=4205016633 Seq=799808988 Len=0 Win=24818

   0: 000c 295d 6f44 0800 20f5 a3b5 0800 4500    ..)]oD.. .....E.
  16: 0028 c84b 4000 4006 5e21 0a01 0025 0a01    .(.K@.@.^!...%..
  32: 003d 22b2 89db 2fac 1ddc faa3 7639 5010    .=".../.....v9P.
  48: 60f2 cf8b 0000 5555 5555 5555              `.....UUUUUU

I have have had made several projects and mock ups using TCP socket, but this is the first time I have encountered this.

I have a Linux server application on a solaris sparc machine that is supposed to accept a connection from an OCX on a webserver, but there is no data received. I used netstat to verify that the connection was established.

I created a tiny tcp client to connect to act as the web server/ocx, but what happens is at the write it stops there and a timeout never occurs. Even if I left the connection and the wait for a few hours, nothing happens. I have even gone as far as to use setsockopt to make sure a low timeout value is set. Also, on the other end, not data is received, and the select statement does timeout while polling the fd set.

Does anyone have an idea why write or send would not timeout while writing to a sokcet? Also, does anyone know why on the server, the read fd set was not set?

here is the dump from snoop:

solaris61 -> 10.1.0.37    TCP D=8882 S=35111 Fin Ack=1805515051 Seq=897643511 Len=0 Win=49640
10.1.0.37 -> solaris61    TCP D=35111 S=8882 Ack=897643512 Seq=1805515051 Len=0 Win=24818
solaris61 -> 10.1.0.37    TCP D=8882 S=35112 Syn Seq=921698308 Len=0 Win=49640 Options=<mss 1460,nop,wscale 0,nop,nop,sackOK>
10.1.0.37 -> solaris61    TCP D=35112 S=8882 Syn Ack=921698309 Seq=1829645518 Len=0 Win=24820 Options=<nop,wscale 0,nop,nop,sackOK,mss 1460>
solaris61 -> 10.1.0.37    TCP D=8882 S=35112 Ack=1829645519 Seq=921698309 Len=0 Win=49640
solaris61 -> 10.1.0.37    TCP D=8882 S=35112 Push Ack=1829645519 Seq=921698309 Len=2 Win=49640
10.1.0.37 -> solaris61    TCP D=35112 S=8882 Ack=921698311 Seq=1829645519 Len=0 Win=24818

using "snoop -x0 -s1500"

solaris61 -> 10.1.0.37 TCP D=8882 S=35291 Syn Seq=4205016629 Len=0 Win=49640 Options=

   0: 0800 20f5 a3b5 000c 295d 6f44 0800 4500    .. .....)]oD..E.
  16: 0034 e4c7 4000 4006 0000 0a01 003d 0a01    .4..@.@......=..
  32: 0025 89db 22b2 faa3 7635 0000 0000 8002    .%.."...v5......
  48: c1e8 148a 0000 0204 05b4 0103 0300 0101    .è..............
  64: 0402                                       ..

10.1.0.37 -> solaris61 TCP D=35291 S=8882 Syn Ack=4205016630 Seq=799808987 Len=0 Win=24820 Options=

   0: 000c 295d 6f44 0800 20f5 a3b5 0800 4500    ..)]oD.. .....E.
  16: 0034 c849 4000 4006 5e17 0a01 0025 0a01    .4.I@.@.^....%..
  32: 003d 22b2 89db 2fac 1ddb faa3 7636 8012    .=".../.....v6..
  48: 60f4 8ec1 0000 0103 0300 0101 0402 0204    `...............
  64: 05b4                                       ..

solaris61 -> 10.1.0.37 TCP D=8882 S=35291 Ack=799808988 Seq=4205016630 Len=0 Win=49640

   0: 0800 20f5 a3b5 000c 295d 6f44 0800 4500    .. .....)]oD..E.
  16: 0028 e4c8 4000 4006 0000 0a01 003d 0a01    .(..@.@......=..
  32: 0025 89db 22b2 faa3 7636 2fac 1ddc 5010    .%.."...v6/...P.
  48: c1e8 147e 0000                             .è.~..

solaris61 -> 10.1.0.37 TCP D=8882 S=35291 Push Ack=799808988 Seq=4205016630 Len=2 Win=49640

   0: 0800 20f5 a3b5 000c 295d 6f44 0800 4500    .. .....)]oD..E.
  16: 002a e4c9 4000 4006 0000 0a01 003d 0a01    .*..@.@......=..
  32: 0025 89db 22b2 faa3 7636 2fac 1ddc 5018    .%.."...v6/...P.
  48: c1e8 1480 0000 750a                        .è....u.

10.1.0.37 -> solaris61 TCP D=35291 S=8882 Ack=4205016632 Seq=799808988 Len=0 Win=24818

   0: 000c 295d 6f44 0800 20f5 a3b5 0800 4500    ..)]oD.. .....E.
  16: 0028 c84a 4000 4006 5e22 0a01 0025 0a01    .(.J@.@.^"...%..
  32: 003d 22b2 89db 2fac 1ddc faa3 7638 5010    .=".../.....v8P.
  48: 60f2 cf8c 0000 5555 5555 5555              `.....UUUUUU

solaris61 -> 10.1.0.37 TCP D=8882 S=35291 Fin Ack=799808988 Seq=4205016632 Len=0 Win=49640

   0: 0800 20f5 a3b5 000c 295d 6f44 0800 4500    .. .....)]oD..E.
  16: 0028 e4ca 4000 4006 0000 0a01 003d 0a01    .(..@.@......=..
  32: 0025 89db 22b2 faa3 7638 2fac 1ddc 5011    .%.."...v8/...P.
  48: c1e8 147e 0000                             .è.~..

10.1.0.37 -> solaris61 TCP D=35291 S=8882 Ack=4205016633 Seq=799808988 Len=0 Win=24818

   0: 000c 295d 6f44 0800 20f5 a3b5 0800 4500    ..)]oD.. .....E.
  16: 0028 c84b 4000 4006 5e21 0a01 0025 0a01    .(.K@.@.^!...%..
  32: 003d 22b2 89db 2fac 1ddc faa3 7639 5010    .=".../.....v9P.
  48: 60f2 cf8b 0000 5555 5555 5555              `.....UUUUUU

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哎呦我呸! 2024-10-11 09:33:21

进入 tcpdump(1) 和/或 snoop(1M) 查看线路两侧的情况。考虑到您描述的“魔法”,这可能是寻找解释的最佳选择。当您找到更多详细信息时,请发布它们。

Get down to tcpdump(1) and/or snoop(1M) to see what goes on on the wire on both sides. This is probably the best option for finding an explanation considering the "magic" you describe. Post more details as you find them.

情栀口红 2024-10-11 09:33:21

仅当未收到已发送内容的 TCP 确认时,才会出现超时。您的转储显示所有发送的数据均已确认,因此不应该有超时。发送的唯一数据是来自Solaris61 的2 个字节。

听起来您是在说您打算将一些数据发送到solaris61。该数据从未发送过。你如何发送这些数据?如果您使用缓冲 stdio 进行写入,则数据可能仍在缓冲区中。例如,如果它是行缓冲的,那么它将被缓冲,直到发送换行符。相反,您可以使用 setvbuf() 关闭缓冲,或者仅使用 send() 直接发送数据。

(如果您已经这样做了,请发布该部分代码。)

You would only get a timeout if it was not getting back a TCP acknowledgment for something that was sent. Your dump shows that all sent data was acknowledged, so no there should be no timeout. The only data that was sent was 2 bytes from solaris61.

It sounds like you are saying that you intended to send some data TO solaris61. This data was never sent. How are you sending this data? If you are writing using buffered stdio then the data may still be in the buffer. For example if it is line buffered then it would be buffered until a newline is sent. Instead you could turn off buffering using setvbuf() or just use send() to send the data directly.

(If you are already doing this then please post that part of the code.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文