Golang implementation of real-time communication based on WebSocket-goeasy

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Golang WebSocket Real-time message push

Here I record how to implement the server-side real-time communication with the client:

The implementation steps are as follows:

1. Get Goeasy Appkey.

Register an account on the Goeasy website and create a new app. After the app is created, the system automatically generates two keys for the app, one that can be used for both receiving and pushing (supper key), and the other to receive (Subscriber key).

2. The client subscribes to a channel.

A. Introducing Goeasy.js to the client, JS address: http://cdn.goeasy.io/goeasy.js

It is important to note that Goeasy.js cannot be downloaded locally, because Goeasy will provide different JS depending on the browser. The official web site also has a corresponding explanation.

B. Subscription code

var goeasy = new Goeasy ({appkey: ' subscriber key '});//I'm using subscriber key here, because I don't need to push any messages on my client, so there's no need to use supper key

Goeasy.Subscribe({Channel:' Csdnnotification ',OnMessage: function (message) {alert (' Meessage received: '+message.content);//received a push message}                });

3. Push the background to the same channel. RESTful API implementations with Goeasy

API Url:http://goeasy.io/goeasy/publish

Mode: Post

Parameter list:

Channel:' Csdnnotification ' //The channel must be consistent with the subscription, otherwise the client will not receive the message. So we can also control which clients can receive according to the channel. Appkey:' supper key ' //must use supper key herecontent:' BlaBla ... ' //What to push

The

wants to be helpful to everyone.

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.