Socket编程的未来和HTML5的WebSocket和休息相结合 [英] Future of Socket Programming and HTML5 WebSocket and REST Combined
问题描述
我在PHP创建简单的socket服务器,并与该聊天应用。
I have created simple Socket Server in PHP and Make Chat Application with that.
插座服务器某些端口上的工作例如127.0.0.1:9999
所有的客户端连接与IP:端口和摇手头的服务器和交流彼此
Socket server working on some port e.g. 127.0.0.1:9999 All clients connect with that IP:PORT and Shake-hand to server and communicate with each other.
我的理念:
1)浏览器
=>获取通过实时通知(的WebSocket)
2)用户
=>帖子(要保存在数据库评论或者使用REST或简单)
救了我的邮政数据库后应该广播到所有的用户界面没有任何 HTTP请求
(仅WebSocket的)。
1) Browser
=> Get Real-time Notifications by ( WebSocket )
2) User
=> Post Comments ( Want to Save Comment in Database either using REST or simple )
After saving my Post to Database It should be broadcast to all users GUI without any HTTP Request
( By Only WebSocket ).
所以,我的问题是关于,如何处理第二部分里面时,有网友发帖评论我的 WebSocketServer
。
So, My question is regarding, How to handle Second Part when User post comment inside my WebSocketServer
.
推荐答案
我猜你可能有一点是这样的:
I guess what you might have in mind is something like this:
浏览器
|
+ ----> REST / HTTP ---> Web服务器(REST)
| |
| (*)
| |
| v
+ - < ---的WebSocket< --- WebSocket的服务器
浏览器就REST / HTTP请求,并同时保持了WebSocket连接到接收实时通知。
The browser does REST/HTTP requests, and at the same time maintains a WebSocket connection to receive real-time notifications.
浏览器就REST / CRUD请求您的Web / REST服务器,并在REST服务器执行CRUD操作,它不仅回答请求,而且还可以通过WebSocket的。发送通知给其他人。
The browser does REST/CRUD requests to your Web/REST server, and when the REST server performs a CRUD operation, it not only answers to the requestor, but also sends out notification to others via WebSocket.
有两个重要的方面:
首先,WebSocket的是不够的,因为它是唯一的原始点对点通信)。你可能会想一些发布和放大器;订阅上的WebSocket 的顶部模式的,以便对给定资源的CRUD操作可发出通知,只有那些浏览器/ WebSocket的客户有兴趣,并允许收到通知相应的资源。
First, WebSocket isn't enough, since it is only raw point-to-point messaging). You likely want some "Publish & Subscribe" schema on top of WebSocket, so that the CRUD operation on a given resource can send out a notification only to those browser/WebSocket clients that are interested and allowed to receive notification for the respective resource.
二,根据您的Web服务器的技术,你想使()尽可能地简单(如做(的),通过一个简单的HTTP请求的从的Web服务器的到的WebSocket的服务器)。
Second, depending on the technology of your Web server, you want to make the () as easy as possible (e.g. doing () by a simple HTTP request from your Web server to the WebSocket server).
两者的上方例如提供由 Crossbar.io :
Both of above is provided e.g. by Crossbar.io:
- Crossbar.io是 WAMP 路由器和WAMP(Web应用程序消息协议)规定发布&放;订阅过的WebSocket
- Crossbar.io有一个内置的HTTP到WAMP的桥梁,可以让你做一个普通的旧式HTTP请求进行发布。
- Crossbar.io is a WAMP router, and WAMP ("The Web Application Messaging Protocol") provides "publish & subscribe" over WebSocket.
- Crossbar.io has a builtin HTTP-to-WAMP bridge that allows you to publish by doing a plain old HTTP request.
请参见这里一个例子。
披露:我与下属和WAMP Crossbar.io
Disclosure: I am affiliated with WAMP and Crossbar.io.
这篇关于Socket编程的未来和HTML5的WebSocket和休息相结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!