通过 http 从服务器到客户端的未经请求的通知
我正在开发类似保管箱的系统,我想知道当服务器端的文件发生更改时客户端如何收到通知。我的印象是 dropbox 和 ubuntu 都通过 HTTP 端口运行,工作原理如下: 1. 如果客户端计算机上的文件发生更改,inotify 会检测到它并执行从客户端到服务器的推送。 (我明白这部分) 2. 如果服务器上的文件发生更改,则会从服务器向客户端发送一个简单的未经请求的通知(仅一条消息“同步时间”)。然后客户端向服务器发起同步。
我真的不在乎我用哪种语言来做这件事。我只是想知道如何联系客户。具体来说,如果客户端位于防火墙后面并拥有自己的本地 IP 地址,该怎么办?服务器如何定位它?
另外,什么样的消息传递协议会被用来做这样的事情?我计划通过 HTTP 或 SSH 执行此操作,但我没有附件执行此操作。
I am working on a dropbox like system and I am wondering how the client gets notified when the files change on the server side. It is my impression that both dropbox and ubuntu one operate over HTTP ports and work as follows:
1. if files change on client machine, inotify detects it and preforms a push from the client to the server. (I get this part)
2. if files change on the server a simple unsolicited notification (just a message saying "time to sync") is sent from the server to the client. Then the client initiates a sync to the server.
I dont really care which language I do this in. I am just wondering how the client gets contacted. Specifically, what if a client is behind a firewall with its own local IP addresses. How does the server locate it?
Also, what kind of messaging protocols would be used to do something like this? I was planning on doing this over HTTP or SSH, but I have no attachment do that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定 Dropbox 使用的是什么,但它可能是 websockets (不太可能,它是一个相当新的、没有广泛部署的东西)或者更可能是从客户端到服务器的待处理的 Ajax 请求——服务器只有在有新的东西给客户端时才会响应。后者是使用 HTTP 实现(好吧——“黑客”;-)某种形式的“服务器推送”的常见方法。
I'm not sure what Dropbox is using, but it could be websockets (unlikely, it's a pretty new and not widely deployed thing) or more likely a pending Ajax request from the client to the server -- to which the server only responds when it has new stuff for the client. The latter is the common way to implement (well, OK -- "hack";-) some form of "server push" with HTTP.
我对网络进行了一些研究才能了解其工作原理,但它比我预期的要简单得多。我现在为此使用标准 Java 套接字。启动监听套接字连接的服务器进程。然后启动连接到服务器的客户端。
一旦建立连接,就可以发回消息。这是通过 NAT(网络地址转换)实现的,NAT 是在防火墙后面的专用网络上路由数据包的标准方法。
It took a little research into networking to see how this would work, but it is far more trivial then I expected. I am now using standard Java sockets for this. Start up the server process which listens for a socket connection. Then start up the client which connects to the server.
Once the connection is made, messages can be sent back and fourth. This works through NAT (network address translation) which is standard method for routing packets on private networks behind a firewall.