O'Reilly logo

Node Cookbook Second Edition by David Mark Clements

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Remote Procedure Calls with Socket.IO

With socket.io, we can execute a callback function over WebSockets (or a relevant alternative). 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 functionalities between clients and servers—it's called Remote Procedure Calls (RPC).

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 a Base64 encoded (http://en.wikipedia.org/wiki/Base64) sentence back to the client.

Getting ready

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

How to do it...

On our server, as before, we load ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required