You can download and run the image file of XPUSH at the docker repository. it is possible to install and run and, in this way, you can be most easily and quickly experience the XPUSH.
XPUSH Docker image files is shared in docker hub, You can download the image to your server or personal PC, and then you can install and run the xpush with it.
Docker Installation By referring to the link, install the Docker.
XPUSH Docker image which we provide is the already configured completely. You can download the XPUSH image file as follows.
docker pull stalk/xpush:standalone
MongoDB and Redis and Zookeeper are installed in the downloaded image, and You can run the session server and channel server as a stand-alone.
Now, you can run the image that you downloaded in Docker environment.
docker run -d –name xpush -p 8000:8000 -p 9000:9000 stalk/xpush:standalone /bin/bash xpush-stand-alone.sh
8000 port is a port number that Session server uses, 9000 port is the port number that Channel server uses. Xpush server that have been executed is accessible to 127.0.0.1.
To access to XPUSH server that you run in docker in OSX, you can obtain an IP address by using the following command. More info
boot2docker ip
Include the XPUSH client library
<script type="text/javascript" charset="utf-8" src="xpush.min.js"></script>
Create the xpush Object
// parameter : server to connect, applicationId
var xpush = new XPush('http://127.0.0.1:8000', 'sample');
When you create a XPUSH instance, The first argument, it is session server address of XPUSH. The server address to be used in the code is only session server. As a result, XPUSH library will let you automatically connect to find the Channel server internally.
Now, I will generate a channel for the message received.
xpush.createSimpleChannel('channel01', function(){
console.log( 'create simple channel success' );
// Output the data to the screen that comes in `message` event.
xpush.on( 'message', function(channel, name, data){
console.log( channel, name, data );
});
});
Create a channel named channel01
.
Channels are used as the address to send and receive messages, can be thought of as chat room in chatting program. Register a function to be called when it is created after the event occurred.
When the event named message
occurs, the will be printed at the console.
Now, We can send the string “Hello World” to message
events in channel01
channel. String as well, JSON type is also available.
xpush.send( 'channel01', 'message', 'Hello World' );
We will implement a simple chat in such a way as described above.
Full source can be found in here.
The XPUSH server that was used in the demo below is a server for temporary test provided by the XPUSH development team, can not operate temporarily, it is not possible to guarantee the performance. So, please use the XPUSH on your own.