简体   繁体   English

套接字连接窗口

[英]Socket Connections Windows

I have a Client Server application written in C# 我有一个用C#编写的客户端服务器应用程序

The server listens on a specified port. 服务器在指定的端口上侦听。 A client pushes data to this server and the remaining clients pull this data. 客户端将数据推送到该服务器,其余客户端则拉出该数据。 Likewise all the clients use this server. 同样,所有客户端都使用此服务器。

I wanted to know, is there any cap on the number of connections that a socket can allow with reliable communication of data, as-in without data loss? 我想知道,套接字可以允许在不丢失数据的情况下进行可靠的数据通信的连接数没有上限吗? Typical size of the data that is communicated to the server and then relayed to the clients is around 40 kbps. 传送到服务器然后中继到客户端的数据的典型大小约为40 kbps。

Can you please help me understand what all parameters should be considered for designing such a solution? 您能帮我了解设计这样的解决方案应考虑所有参数吗?

Upstream bandwidth will be your biggest bottleneck. 上行带宽将是您最大的瓶颈。 If by "40 kbps" you mean kilo-BITS per second instead of kilo-BYTES per second then that gives you 5 KB/s. 如果以“ 40 kbps”表示每秒千比特,而不是每秒千比特,那么您的速度为5 KB / s。 If your upstream bandwidth is 1 mega-BIT per second (128 kilo-BYTES per second) then you can only have around (128/5) 25 clients. 如果您的上行带宽是每秒1兆BIT(每秒128千字节),那么您只能拥有大约(128/5)25个客户端。

For the allowing many connections on one port issue, HTTP servers do this without a problem. 对于允许在一个端口上进行许多连接的问题,HTTP服务器可以毫无问题地进行此操作。

Actually one socket will not handle all the data in the server. 实际上,一个套接字不会处理服务器中的所有数据。 In the server you have a listen socket which only purpose is to accept incoming connections from your clients. 在服务器中,您有一个侦听套接字,其唯一目的是接受来自客户端的传入连接。 Then you get one connection/socket per client. 然后,每个客户端获得一个连接/套接字。

The operating system will try to evenly distribute the bandwidth among all connected sockets (yours and other applications). 操作系统将尝试在所有连接的套接字(您和其他应用程序)之间平均分配带宽。 UDP sockets have higher priority than TCP sockets. UDP套接字的优先级高于TCP套接字。

The server can treat as many clients as you like as long as the network bandwidth can handle it. 只要网络带宽可以处理,该服务器就可以根据需要处理任意数量的客户端。 If got got a few clients you can use threads for the sockets/clien t, while if you got many I suggest you read up on asynchronous handling (the BeginXX/EndXX methods). 如果有几个客户端,则可以将线程用于套接字/客户端,而如果有很多客户端,则建议您阅读异步处理(BeginXX / EndXX方法)。

If bandwidth is a problem you should throttle the sends and receives (the easiest approach is to use Thread.Sleep) to not choke the network connection. 如果带宽有问题,则应限制发送和接收(最简单的方法是使用Thread.Sleep),以免阻塞网络连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM