DEV Community

Cover image for ☎️ Ways to communicate between browsers and servers and everything in between.☎️
Adam Crockett
Adam Crockett

Posted on

☎️ Ways to communicate between browsers and servers and everything in between.☎️

I have been looking at the ways things can talk to other things.

I have found a few reasonable ways, some you might know already. I should mention, this is from the perspective of a JavaScript engineer. Lastly, the intention of this post is to give a high-level overview, there may be comparisons and humor to cover my lack of knowledge on some of the listed technologies `#knowWhatYouNeed, if you know, tell us more and I will add this to the post.

Browser to Browser

  • WebRtc is a way of communicating P2P without a server being the broker, unlike websockets, WebRtc says to the host, "hi I need to talk to that browser let me connect to them directly and securely... but server, I don't need you anymore, go away". This is the underlying technology of Google hangouts and other web based meeting / chat apps. What might not be so obvious is that webrtc can send text based data it doesn't have to be video or audio which makes it a faster safer alternative to websockets.

The spec -

Browsers to Server, Server to Browsers

  • Websockets are real time tcp sockets connected to the web, they do require a server throughout any communications, they send data bi-directionally, they are a noticibly slower. They do not reconnect you if a client looses connect, you have to handle that.
  • cookies, a string of delimited text that can hold arbitrary information, it can be accessed on response or in browser.

Server to Browser

  • Server Sent Events, it's a realtime stream of data mounted to a URL, JavaScript EventSource will allow all clients to listen to data in the stream sent by the server. It's kind of like half a websocket because you cannot send data back. They automatically reconnect which would have been great for a PWA if it weren't for the fact that there was no internet at the time 🤦‍♂️, SSE is fast.

Browser to Server

  • Post and Put requests can send data bodies between client and server, this is not realtime, but this might not matter, pair this with SSE if you want to.

Server to Server

  • TCP it's like the internet for your local network 🔦 (http 1 and 2 are TCP based)
  • UDP it's like the internet for your local network except it's got no f***s to give and will send data extremely quickly at anything and nothing ⚫

That's all we have time for folks. 😍
Missed anything? Let me know in the comments.

Top comments (0)