Cover by David Mark Clements

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Callbacks over socket.io transport

With socket.io we can execute a callback function over WebSockets (or a relevant fallback). The function is defined client side, yet called server side (and vice versa). This can be a very powerful way to share processing resources and functionality between clients and servers.

In this recipe, we'll create a way for the server to call a client-side function that squares a number, and for the client to call a server-side function that sends Base64 encoding (http://en.wikipedia.org/wiki/Base64) of a sentence back to the client.

Getting ready

We simply need to create a new folder with new client.html and server.js files.

How to do it...

On our server, as before, we load our http module and the client.html file, create ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required