测试“积压"有问题根据 ServerSocket(int port, int backlog) [英] Having issue with testing "backlog" as per ServerSocket(int port, int backlog)

查看:55
本文介绍了测试“积压"有问题根据 ServerSocket(int port, int backlog)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 ServerSocket(int port, int backlog), backlog 表示队列的最大长度.

As per ServerSocket(int port, int backlog), backlog indicates maximum length of the queue.

我使用以下代码创建了一个简单的服务器套接字,backlog 为 1 ServerSocket serverSocket = new ServerSocket(8001, 1); 我的期望是当我尝试使用超过 1 个客户端连接到此服务器,然后我将收到连接被拒绝的异常.

I created a simple server socket, with backlog as 1 using following code ServerSocket serverSocket = new ServerSocket(8001, 1); and my expectation was that when I will try to connect to this server with more than 1 client then I will get connection refused exception.

但是当我尝试从 1 个以上的客户端连接到这台服务器时,我什至可以并行连接 3 个客户端,并且所有客户端都能够与服务器通信.

But when I tried to connect with this server from more than 1 client then I was able to connect even with 3 client in parallel and all were able to communicate with the server.

我错过了什么吗?

推荐答案

backlog 参数可以由平台上下调整.在 BSD 4.3 中,实际的最小积压最初是 5,现在在某些平台上更像是 50 甚至 500.没有 API 来确定实际使用的值.

The backlog parameter can be adjusted up or down by the platform. The actual minimum backlog was initially 5 in BSD 4.3 and it is now more like 50 or even 500 on some platforms. There is no API to determine the actual value used.

这篇关于测试“积压"有问题根据 ServerSocket(int port, int backlog)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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