积压已满时,为什么不拒绝ServerSocket连接? [英] Why aren't ServerSocket connections rejected when backlog is full?

查看:39
本文介绍了积压已满时,为什么不拒绝ServerSocket连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无私的好奇心...

在Java中,我在套接字上侦听,积压为1:

In Java I listen on a socket, with backlog of 1:

ServerSocket ss = new ServerSocket(4000, 1);

在shell中运行

netcat localhost 4000

很多次-到目前为止有5次.

many times - 5 so far.

连接永远不会被拒绝. netcat 的每个实例都坐着等待,直到我的ServerSocket被销毁.

The connections are never rejected. Every instance of netcat sits and waits until my ServerSocket is destroyed.

待办事项的长度为1-这意味着它只应让一个传入的连接排队,然后拒绝,不是吗?(((我不知道队列中是否包含第一个队列-现在不重要.))

Backlog length is 1 - that means it should only let one incoming connection queue up, and then reject, does it not? ((I don't know if the queue includes the first one - not important right now.))

我知道我可以通过关闭ServerSocket(然后在我准备好时再打开一个)来使它工作,但是...还是不行吗?

I know I can make this work by closing the ServerSocket (and then opening another one when I'm ready), but... shouldn't it work anyway?

我误会了吗?

推荐答案

我在在此处写道,

此行为与平台有关.当积压填满时,Windows会发出RST,这将导致连接被拒绝".Unix,Linux只是丢弃SYN数据包.

This behaviour is platform-dependent. Windows issues an RST when the backlog fills up, which results in 'connection refused'. Unix, Linux just drop the SYN packet.

NB Backlog长度不是1.平台可以向上或向下调整它.在BSD早期版本中,历史上最小的最小积压长度是5.现在在某些平台上是五十甚至五百.

NB Backlog length isn't 1. The platform can adjust it up or down. The smallest minimum backlog length in history was five, in early BSD releases. It is now fifty or even five hundred on some platforms.

这篇关于积压已满时,为什么不拒绝ServerSocket连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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