Shawn Mervin

Socket.IO

A realtime messaging library for Node.js, and the engine of Rental Pilot's chat across web and phone.

Visit socket.ioBehind it

What it is

Socket.IO is a JavaScript library for realtime, two-way communication between a server and its clients. It runs on Node.js on the server, with client libraries for browsers and other platforms. Messages are sent as named events, which keeps the code readable. Clients can listen for any event by name and reply with their own, which suits chat, live dashboards and collaborative screens.

It uses WebSockets where it can and falls back to HTTP long-polling where it cannot. It adds what raw WebSockets leave out: automatic reconnection, acknowledgements, and rooms, which let a server send a message to a group of connected clients at once. Socket.IO uses its own protocol on top of WebSocket, so a Socket.IO client is needed to talk to a Socket.IO server.

How I use it

  • Rental Pilot's chat server is a Node app on Socket.IO, behind nginx over secure WebSockets and run by systemd on the EC2 server.
  • Direct messages and groups across the web and phone apps, with typing, presence, read and delivered ticks, reactions, @mentions, pins and attachments.
  • Each connection is authenticated with an HS256 JSON Web Token signed by the PHP API and checked by the chat server.
  • People who are not connected get an Expo push notification instead.

Socket.IO is the right tool when an app needs live updates such as chat or presence and the team wants reconnection and rooms handled for them. I reach for it because field staff and the office need to talk inside the app they already use, on bad connections as well as good ones.

Questions

Can you add live chat to my business software?

Yes. Rental Pilot has chat built in across web and phone, with groups, read ticks, reactions and attachments, running on a Socket.IO server I operate.

How is the chat kept private?

Every connection must present a signed token issued by the API, which the chat server checks before letting it join. Traffic runs over secure WebSockets behind nginx.

Working with Socket.IO?

Tell me what you're building. Start a project or see the whole stack.

Got an operation that's outgrown its spreadsheets?

Tell me what your business does and where it's jamming up. If I'm not the right person for it, I'll say so and point you somewhere better.

What to send, and what happens next