一个服务器可以在不同的端口上处理多少个TCP连接? [英] How many tcp connections on different ports a sever can handle?

查看:664
本文介绍了一个服务器可以在不同的端口上处理多少个TCP连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C#设计服务器客户端应用程序. 客户端与服务器tcp套接字进行连接并进行通信.

在服务器端,我正在使用socket.accept()方法来处理来自客户端的新连接.当客户端连接时,服务器使用随机端口以与客户端进行通信.

所以我的问题是..服务器可以以这种形式接收多少个客户端? 为了处理很多客户,我还应该使用另一种形式吗?

解决方案

在服务器端,我正在使用socket.accept()方法来处理来自客户端的新连接.当客户端连接时,服务器使用随机端口以与客户端进行通信.

除非您打开从服务器到客户端的另一个无意义的连接,否则不会这样做,因为防火墙的原因.接受的套接字使用与侦听套接字相同的本地端口号.与这里的几个答案和评论相反.

因此,您的问题基于错误的观念.无论用尽什么,它可能是内存,线程句柄,套接字句柄,套接字缓冲区空间,CPU,CPU能力,虚拟内存,磁盘空间等,...都不会是TCP端口.

编辑新随机端口理论的拥护者需要解释以下netstat输出:

TCP    127.0.0.4:8009         0.0.0.0:0              LISTENING
TCP    127.0.0.4:8009         127.0.0.1:53777        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53793        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53794        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53795        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53796        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53798        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53935        ESTABLISHED

并显示 RFC 793 中的位置,该内容说明了有关将新端口分配给可接受的套接字的任何内容,以及在TCP连接握手交换中传送新端口号的位置.

I am designing a server client app in C#. the client connect and communicate with the sever threw tcp socket.

in the server side I am using the socket.accept() method in order to handle new connection from client. when client is connecting, the server use a random port in order to communicate with the client.

so my question is.. how many clients the server can receive in this kind of form? is there another form that I should use in order to handle lots of clients?

解决方案

in the server side i am using the socket.accept() method in order to handle new connection from client. when client is connecting, the server use a random port in order to communicate with the client.

Not unless you open another, pointless, connection from server to client, and you won't be doing that for firewall reasons. The accepted socket uses the same local port number as the listening socket. Contrary to several answers and comments here.

Your question is therefore founded on a misconception. Whatever you run out of, and it could be memory, thread handles, socket handles, socket buffer space, CPUs, CPU power, virtual memory, disk space, ..., it won't be TCP ports.

EDIT Adherents of the new-random-port theory need to explain the following netstat output:

TCP    127.0.0.4:8009         0.0.0.0:0              LISTENING
TCP    127.0.0.4:8009         127.0.0.1:53777        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53793        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53794        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53795        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53796        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53798        ESTABLISHED
TCP    127.0.0.4:8009         127.0.0.1:53935        ESTABLISHED

and show where in RFC 793 it says anything about allocating a new port to an accepted socket, and where in the TCP connect-handshake exchange the new port number is conveyed.

这篇关于一个服务器可以在不同的端口上处理多少个TCP连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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