francois1

francois1

Difference between Phoenix JS Socket and WebSocket API?

Hello,

What is the difference between the Phoenix JS Socket

import { Socket } from 'phoenix';

and the native JS WebSocket API ?

I suppose the Phoenix JS Socket uses the WebSocket API behind the scenes and adds functionalities over it? I I got this right, what value/functionalities does it add over the native WebSocket API?

Thank you for any help!

Marked As Solved

03juan

03juan

Hi and welcome to the forum.

A Phoenix.Socket is a module that ties a communication transport layer to Phoenix.Channels that handle real-time communication between clients and Elixir processes (live LiveViews). It’s an abstracted transport layer that can communicate over native websockets but can fall back to longpolling mechanisms if needed. So you’re able to develop real-time communications in exactly the same way irrespective of the connection, and can even implement your own transport layer through the Phoenix.Socket.Transport behaviour.

Also Liked

chrismccord

chrismccord

Creator of Phoenix

In addition to what Juan said, the websocket transport provides a number of features on top of websockets, such as:

  • heartbeats
  • connection recovery
  • request/response messaging
  • multiplexed channels of communication over single connection

Last Post!

chrismccord

chrismccord

Creator of Phoenix

In addition to what Juan said, the websocket transport provides a number of features on top of websockets, such as:

  • heartbeats
  • connection recovery
  • request/response messaging
  • multiplexed channels of communication over single connection

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130579 1222
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement