通过互联网进行通信

发布于 2024-11-28 16:00:12 字数 309 浏览 1 评论 0原文

如果以前有人问过这个问题,我很抱歉,但这个想法很难表述。我可以理解两台计算机如何通过监听开放端口并将信息直接发送到IP地址来直接交互。但是,我想知道 LogMeIn 或聊天应用程序等应用程序如何通信(我猜测是通过端口 80,因为它始终打开,但不允许您收听它),甚至游戏(如果它们未打开)一个端口)。如果我猜测的话,我会认为他们使用带有数据库的第三方网络服务器,通过“GET”和“POST”请求来协调计算机之间的信息传输。这可能会使通信异步。

只要我能得到答案,我不在乎这个问题是否得到不好的评价,即使它只是指向其他有答案的地方的链接。另外,我主要从事C++工作,熟悉TCP和HTTP协议。

I'm sorry if this question has been asked before, but the idea is hard to formulate. I can understand how two computers can directly interact by listening to open ports and sending information directly to IP addresses. However, I want to know how applications like LogMeIn or chat applications communicate (through port 80 I'm guessing because it is always open, but you aren't allowed to listen to it), or even games (If they don't open a port). If I was to guess, I would think that they use a third party web server with a database that mediates the transfer of information between the computer by "GET"ing and "POST"ing requests. That would probably make the communication asynchronous.

I don't care if I get a bad rating for this question so long as I can get an answer, even if it is just a link to somewhere else that has the answers. Also, I work in C++ mainly and I am familiar with TCP and HTTP protocols.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

素罗衫 2024-12-05 16:00:12

是的,通常有一个“服务器”可供多个客户端连接。服务器接受来自一个客户端的消息并将其转发给一个或多个其他客户端。这几乎总是“异步”,但这可能意味着一些事情(无论是在客户端还是服务器上以这种方式完成,服务器是否是“事件驱动”或多线程等)。服务器可以是 Web 服务器,但也存在其他类型(例如 Jabber 服务器,它使用 XMPP,通常[或经常]在端口 5222 上)。

一些信使通过 HTTP(通常是端口 80,通常是开放的)工作,即使协议通常使用不同的端口,也可以编写一个“Web 网关”来通过端口 80 和 HTTP 进行通信,以避免其他端口被阻止的问题,并且它可以转发到“标准服务器”或完全重新实现它。特别是在企业环境中,互联网访问可以通过 HTTP 代理服务器进行中介,因此使用网关或本机 HTTP 消息应用程序/协议是唯一的选择。

我想对于这些讨论正确定义“服务器”很重要。该术语通常用于描述位于数据中心或其他地方的实际计算机。但是,当我们谈论“Web 服务器”或“jabber 服务器”时,我们通常指的是软件守护进程,它是一个软件,其工作是侦听客户端连接并根据收到的消息采取行动。

Yes, generally there is a 'server' that multiple clients connect to. The server accepts messages from one client and forwards it to one or more other clients. This is almost always 'asynchronous' but that can mean a few things (whether it is done that way on the client or server, whether the server is 'event driven' or multithreaded, etc). The server can be a web server, but other kinds exist (Jabber servers for example, which use XMPP, usually [or often] on port 5222).

Some messengers work over HTTP (usually port 80, usually open) and even when a protocol usually uses a different port, a 'web gateway' can be written to communicate over port 80 and HTTP to avoid problems with other ports being blocked, and it can forward to the 'standard server' or re-implement it entirely. Especially in corporate environments, internet access can be me mediated by an HTTP proxy server so using a gateway or native HTTP messaging apps/protocols is the only option.

I guess it's important to define 'server' correctly for these discussions. Often the term is used to describe an actual computer, sitting in a data center or something. But when we talk about a 'web server' or 'jabber server' we usually mean a software daemon that is a piece of software who's job it is to listen for client connections and act on the messages it receives.

南冥有猫 2024-12-05 16:00:12

您是对的,在客户端之间传递信息的服务器很常见。 IRC 和大多数在线游戏都是这样工作的。有些应用程序确实使用 HTTP 只是为了避免防火墙问题。

互联网上的所有通信本质上都是异步的:在调用函数写入套接字后,程序将继续运行,同时数据包传输到其目的地。

You're right that it's common to have a server which relays information between clients. IRC works that way, and most online games. And some applications do use HTTP just to avoid firewall troubles.

All communication on the Internet is inherently asynchronous: after you call a function to write to a socket, your program continues running while the packet travels to its destination.

殊姿 2024-12-05 16:00:12

另一种替代方案是点对点网络,其中中央服务器将协商两个客户端之间的直接连接,并主要充当客户端及其相关直接链接状态的仲裁者,而不是充当代理或中间人转发客户端之间的消息。因此,客户端将向中央服务器发送请求,请求连接到另一个客户端,服务器将从寻找其他对等点连接的客户端池中找到其他客户端,并将每台机器的信息发回到对面的客户端,此时客户端本身将相互建立直接连接。一旦建立了两个客户端之间的对等连接,服务器就可以维护客户端及其关联连接的“状态”(即,有X数量的机器从某个单独的客户端机器拉出)。

Another alternative is a peer-to-peer network where a central server will negotiate a direct connection between two clients, and mainly serve as an arbiter for the status of the clients and their associated direct link rather than as a proxy or middle-man forwarding messages between clients. So a client will send a request to the central-server asking for a connection to another client, and the server will find that additional client from a pool of clients looking for other peers to connect to, and send the information for each individual machine back to the opposite client, at which point the clients themselves will make a direct connection to each other. Once the peer-to-peer conection between the two clients is established, the server may then maintain a "status" on the clients and their associated connections (i.e., there are X number of machines pulling from some individual client machine).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文