Moving from Socket.io to Ably

Below is a guide to some of the basic transitioning from Socket.io to Ably. For more help, please get in touch with us and we'll be happy to help you.
 
The socket.io API is actually very similar to the Ably API, if you take a look at our quick start guide: https://www.ably.io/documentation/quick-start-guide
To connect
 
In socketIO: 
io.on('connection', (socket) => {
  console.log('a user connected');
});
 
in Ably:
ably.connection.on('connected', function() {  
    alert("That was simple, you're now connected to Ably in realtime");
});
 
Sending a message:
In SocketIO:
io.on('connection', (socket) => {
   socket.broadcast.emit('message-name', 'hello there this is my message');
});;
 
In Ably, you need to first have a channel set up and then you can send and receive on that channel:
var channel = ably.channels.get('test-channel');
channel.publish('message-name', 'hello there this is my message');
 
To receive a message:
 
In SocketIO:
socket.on('message-name', (message) => {
    console.log('message was: ' + message);
});
 
In Ably any subscribers to the channel that you created will receive the message:
channel.subscribe('test-channel', function(message) {
  console.log('message was: ' + message.data);
});