njarin / websockets

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WebSockets

What are WebSockets? Why use them?

WebSockets provide a persistent connection between a client and server that both parties can use to start sending data at any time.

After making an intial HTTP request, the client makes a WS request, which remains open so that data can be pushed in either direction.

The advantage here is that you can send data in either direction without having to include an entire HTTP request every time. No head and cookies because those can start adding up if you're sending a lot of requests back and forth.

WebSockets are a great tool for any app that needs realtime data, such as a chat or a stock ticker.

Code Demo with DevTools

Open index.html in this repo, then open Chrome DevTools and navigate to the Network tab. This repo contains a simple implementation of websockets.

screenshot of demo with devtools screenshot of demo with devtools

WebSockets and Rails

Get a better look at an implementation of WS with this app that uses Rails 5's Action Cable: Chatty.

There's a tutorial for building this here.

Resources

About


Languages

Language:JavaScript 47.6%Language:CSS 37.6%Language:HTML 14.8%