被动和主动插座 [英] Passive and active sockets

查看:70
本文介绍了被动和主动插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此套接字教程中引用:

套接字有两种主要形式. 活动插座已连接至 通过打开数据的远程活动套接字 连接...无源插座是 没有连接,而是等待 传入连接,这将 一次产生一个新的活动套接字 建立连接 ...

Sockets come in two primary flavors. An active socket is con­nect­ed to a remote active socket via an open data con­nec­tion... A passive socket is not con­nect­ed, but rather awaits an in­com­ing con­nec­tion, which will spawn a new active socket once a con­nec­tion is es­tab­lished ...

每个端口可以有一个被动端口 套接字绑定到它,等待 传入连接,以及 多个活动插座,每个 对应于一个开放 端口上的连接.好像 工厂工人正在等待新的工人 邮件到达(他代表 无源插座),以及当 邮件来自新发件人,他 发起通信(a 连接)与他们 委派他人(主动 套接字)以实际读取数据包 并在发回邮件时回复发件人 必要的.这允许工厂 工人有空接收新的 包. ...

Each port can have a single passive socket binded to it, await­ing in­com­ing con­nec­tions, and mul­ti­ple active sockets, each cor­re­spond­ing to an open con­nec­tion on the port. It's as if the factory worker is waiting for new mes­sages to arrive (he rep­re­sents the passive socket), and when one message arrives from a new sender, he ini­ti­ates a cor­re­spon­dence (a con­nec­tion) with them by del­e­gat­ing someone else (an active socket) to ac­tu­al­ly read the packet and respond back to the sender if nec­es­sary. This permits the factory worker to be free to receive new packets. ...

然后,本教程说明,建立连接后,活动套接字将继续接收数据,直到没有剩余字节为止,然后关闭连接.

Then the tutorial explains that, after a connection is established, the active socket continues receiving data until there are no remaining bytes, and then closes the connection.

我不明白的是:假设端口有一个传入连接,发送方希望每20分钟发送一些数据.如果活动套接字在没有剩余字节的情况下关闭了连接,那么发送方是否在每次要发送数据时都必须重新连接到该端口?我们如何将曾经建立的连接保持更长的时间?你能告诉我我在这里想念什么吗?

What I didn't understand is this: Suppose there's an incoming connection to the port, and the sender wants to send some little data every 20 minutes. If the active socket closes the connection when there are no remaining bytes, does the sender have to reconnect to the port every time it wants to send data? How do we persist a once established connection for a longer time? Can you tell me what I'm missing here?

我的第二个问题是,谁确定同时工作的活动套接字的限制?

My second question is, who determines the limit of the concurrently working active sockets?

推荐答案

发送方应定期发送KEEPALIVE数据包以保持连接有效. KEEPALIVE的格式取决于协议.它可以小到TCP数据段中的单个NULL.

The sender should send a KEEPALIVE packet at regular intervals to keep the connection alive. The format of the KEEPALIVE depends on the protocol. It could be as small as a single NULL in the TCP data segment.

关于第二个问题...取决于I/O.如果它阻止了I/O,则您只希望计算机上运行一定数量的线程,因此您将无法拥有许多客户端.如果是非阻塞的,则可以有更多的客户端.编程语言应同时支持阻塞和非阻塞I/O. (我知道Java就是这样.)

As to the second question... it depends on the I/O. If it is blocking I/O then you only want a certain number of threads running on your computer, so you won't be able to have many clients. If it's non-blocking, you can have a lot more clients. Programming languages should have support for both blocking and non-blocking I/O. (I know for a fact that Java does.)

它还取决于带宽,每个客户端的数据传输,内存,时钟速度等因素.但是非阻塞与阻塞会在可接受的客户端数量上产生巨大差异.在服务器不崩溃的情况下,您可能无法阻止5-10个以上的客户端...但是,如果您不进行阻止,则可以有成千上万个客户端.

It also depends on things like bandwidth, the data transfer for each client, memory, clock speed, etc. But non-blocking vs. blocking can make a huge difference in the number of clients you can accept. You probably can't have more than 5-10 clients blocking without your server crashing... but you can have thousands if you're not blocking.

这篇关于被动和主动插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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