Last Updated: February 25, 2016
·
5.996K
· pixeladed

Webrtc vs Websockets

2 very appealing technology indeed.

WebRTC [web real-time-communication]

Webrtc has recently been realease and is still in beta. It has 3 API: MediaStream, RTCPeerConnection and RTCDataChannel. So why should you care when you already have web sockets?

Media Stream

Well WebRTC allow you to create a media stream + audio stream from the user built-in webcam and microphone (if they have one). Before this, media is pretty strange stuffs. It stream with reasonably good quality.

Peer connection

WebRTC can establish a direct P2P connection between 2 clients. With a little setup from server, you can exchange raw data directly between users. This can be really helpful when you're exchanging a lot of data or even small amount fast and maybe securely.

Data channel

Data channel enable you to create a virtual server and do what you used to do with Web sockets without server. So you no longer have to send data to server and then to clients again.

Web sockets

This particular technology force you to connect all parties to the server and refuse to work without one .Web sockets has been around for a while and we're getting familiar with it but it still have it advantages. Although WebRTC can do Web sockets functionality, connecting to a server and seriously takes someday of your life. So if you wanted to submit form data exchanging back and forth between clients eh........ don't ;). Building a real-time web app with sockets consist of these steps:

  1. Connect clients to server
  2. A client send something to the server
  3. Server receive the message and send it to every other client (may include sender client)
  4. Client[s] receive message and do something with it.

Bottom lines

Although some people might think WebRTC and Web Sockets do the same thing, each serve a different functionalities for different purposes.