The principle of 1.websocket
Refer to this post for details http://blog.csdn.net/hhwell/article/details/44625287
2. Using the WebSocket interface in Workerman
Workerman official website http://www.workerman.net/
Suppose you now have a need to instantly update the list of people watching live
(1) First establish a mapping table with the current process ID and the live video ID, as well as the u_id (user ID) and u_name (user name) fields in the table.
(2) to the official website download Workerman, I environment is window, so I downloaded a window version of the
The introduction of this file in the project will enable you to use the
(4) Client establishes WebSocket connection
OnOpen: Triggered when the connection is successful
OnMessage: Triggered when a message is sent by the server
OnClose: triggered when disconnected
OnError: Triggered when connection error occurs
STR is a string to be transmitted to the server
(5) service-side code
The above code has been annotated, the process is that when the data sent by the client, processing the transmitted string, and then insert the data into the mapping table, when returning data to the client, first check whether there is a record in the database to watch the live broadcast, some words to get the user name, If not, then directly return to the current user (in fact, this is the best use of caching, such as redis processing, but in order to facilitate the description of the data in the database), when disconnected, according to the process ID to delete the records in the mapping table
(6) test
PHP start.php Start Service
Open Browser, Access test.html
Related test code Download:
Simple use of WebSocket