1 of 10

WebSockets

The technology you wish you knew more about…

...until you start using them and realize that you now hate me for introducing them to you in the first place, for “oh so many” reasons...

2 of 10

Who are you and why should I listen?

  • Shane Tarleton
    • Software Engineer at iHeartMedia, Inc.
    • 10+ years doing “full-stack” web development
    • INSANELY dry sense of humor...almost not worth listening to
  • MOST IMPORTANTLY:
    • Don’t listen to me. Do your own research.
  • Social Links (...in case you didn’t read the last bullet)

3 of 10

What are WebSockets?

  • “TLDR” version:
    • WebSockets is the “instant messenger” functionality built directly into web browsers and servers
  • “Technobabble” version:
    • WebSocket is a web protocol built built using a TCP connection, with compatibility for HTTP, to provide web clients and servers a real-time, two-way method of communication 1

4 of 10

Intriguing, but why do I care?

  • Do you remember the first time you...
    • ...used IM or IRC message?
    • ...received a text message?
    • ...got a push notification on your phone?
  • But we already have long-polling in “AJAX”...
    • It requires constantly “pinging” your database 2
    • It is EXTREMELY taxing on web server resources 3

5 of 10

Okaaaaaay...how do I use it?

  • Basically any major server-side web development language*** has it…
    • Java 4
    • C# / F# (using SignalR 5)
    • Python 6
    • Node.js (using WS 7 or Socket.io 8)
    • Ruby (multiple different libraries available)
  • All major browsers across every major device has native support 9
    • Or you can choose to use a library (such as Socket.io) to make it easier

*** not sure about other languages, as these are the only ones I know about or have researched previously

6 of 10

Does anyone use it in production?

  • Couple of apps currently use it...of which I am aware:
    • GitHub (certain use-cases)
    • Slack (almost entirely driven on WebSockets)
    • Transparently (shameless plug for my personal project)

7 of 10

Are there alternatives?

  • Long-polling over HTTP (already spoke about this)
    • Supported in multiple libraries (such as JQuery)
    • Supported in every major browser
  • SSE (Server-Sent Events)
    • Has limited browser support 10
  • There are varying reviews of the techniques 11 12

8 of 10

SHOW ME THE MONEY!!!

  • https://github.com/th3n3wguy/sadevs-websocket-demo
  • Instructions to run it are in the README.md file
    • ...just in case you are crazy enough to try it out yourself (remember what I said earlier?)

9 of 10

10 of 10

Sources / Reading Material