Future of Socket Programming and HTML5 WebSocket and REST Combined [closed]

倖福魔咒の 提交于 2019-12-12 04:46:06

问题


I have created simple Socket Server in PHP and Make Chat Application with that.

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.

My Concept:

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 ).

So, My question is regarding, How to handle Second Part when User post comment inside my WebSocketServer.


回答1:


I guess what you might have in mind is something like this:

Browser | +----> REST/HTTP ---> Web Server (REST) | | | (*) | | | v +-<--- WebSocket <--- WebSocket Server

The browser does REST/HTTP requests, and at the same time maintains a WebSocket connection to receive real-time notifications.

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.

There are 2 important aspects:

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.

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).

Both of above is provided e.g. by Crossbar.io:

  • 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.

Please see here for an example.

Disclosure: I am affiliated with WAMP and Crossbar.io.



来源:https://stackoverflow.com/questions/25301340/future-of-socket-programming-and-html5-websocket-and-rest-combined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!