serversocket类如何在同一端口上提供多个客户端连接? [英] How does serversocket class serve multiple client connections on same port?

查看:960
本文介绍了serversocket类如何在同一端口上提供多个客户端连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用Socket类时,正在建立与某个端口上的服务器的TCP连接,但在服务器上,ServerSocket能够为每个接受请求处理多个客户端连接,并将其委托给一个线程来为请求提供服务。但是,如何使ServerSocket类在同一端口上接受多个tcp连接。

When using a Socket class one is establishing a TCP connection to a server on some port, but on the server the ServerSocket is capable of handling multiple client connections for each accept request and delegate it to a thread to server the request. But how is it possible for a ServerSocket class to accept multiple tcp connections on the same port.

这是否意味着由操作系统决定它允许的连接数或允许的最大积压数是多少,这可以由操作系统上的应用程序控制(我的意思是java受OS支持的最大积压限制)并且TCP规范中的积压连接是否有任何私有权?

Does it mean that it is upto the OS to decide how many connections it allows or what is the maximum backlog allowed and can this be controlled by applications on top of OS(i mean is java restricted by the maximum backlog supported by OS) and is there any privison for backlog connections in TCP specification?

最佳反馈,

Keshav

Best reagards,
Keshav

推荐答案

TCP连接由一组唯一的(源IP,源端口,dest IP,dest端口)定义。由于服务器绑定到特定端口,因此它定义了这4个变量中的两个。只要客户端都来自不同的IP和/或不同的端口,就不会有问题。

A TCP connection is defined by a unique set of (source IP, source port, dest IP, dest port). Since the server binds to a particular port, it defines two of those 4 variables. As long as the clients all come from different IPs and/or different ports, it won't be an issue.

是的,操作系统可以控制总连接数是允许的,你的程序可以进一步限制它。

And yes, the OS can control how many total connections are allowed, and your program can restrict that even further.

这篇关于serversocket类如何在同一端口上提供多个客户端连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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