Small program development of the socket Programming applet live play the development of live barrage using web socket programming

Source: Internet
Author: User
Tags live chat

Recently, there is a project is very hot, that is the live answer, received the company's task, the development of live chat room function. People online chat with each other. Previously done similar, was used by Ajax polling, this is a very expensive server. So this time began to use the socket to do, I am mainly responsible for back-end development, mainly with the front-end to do some interface.

Small program front-end use of space wx.connectsocket do the relevant WSS configuration, and then I use PHP to do the socket service read and write.

The company is using the gateway worker specifically said, you can read his documents ha, I directly on the code

Gatewayworker2.x 3.x Brochure
http://doc2.workerman.net/326102

First small program front end use Wx.connectsocket connection successful socket will return to ClientID, we just use the back-end PHP to do clientid binding, will each live answer exam hall number as a group,

Gateway::joingroup ($clientid$group _id);

The binding was successful. Then the user in the applet sends a message that uses the Curl post message content to the backend PHP interface

Like, not much, I went directly to the code to push messages to all the end customers of a group, so that as long as the front-end sends a message, the backend directly gets the content and pushes it to all the end users. Note that the content of the push Remember to use JSON encoding and then push OH.

Gateway::sendtogroup ($groupName=$redisName$sendDataString);                 $ary [' GroupCount ']= gateway::getclientcountbygroup ($groupName);                 $ary [' Groupclientsession ']= gateway::getclientsessionsbygroup ($groupName);                 $ary [' Getallclientcount ']= gateway::getallclientcount ($groupName);

Well, let's share it with you today. We hope to help you. The recent live broadcast is very hot and hopefully this share will help you develop this live chat room.

I, Qiu Feng, Phper, currently self-employed, to do project system development, PHP back-end plus small program front-end combined with Welcome to exchange everyone to learn from each other together to improve my number: qiufeng2983

Small program development of the socket Programming applet live play the development of live barrage using web socket programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.