arrowsmith

arrowsmith

The default Phoenix Endpoint configures a mount-point for both a websocket and long polling:

defmodule MyAppWeb.Endpoint do
  …

  socket "/live", Phoenix.LiveView.Socket,
    websocket: [connect_info: [session: @session_options]],
    longpoll: [connect_info: [session: @session_options]]

The docs say that this function “defines a websocket/longpoll mount-point for a socket”, but they don’t go into much detail. How does this work? Under what circumstances would my LiveView client connect to the server via long polling instead of a websocket?

Note: I’m not asking what long polling is. I understand that it’s an alternative way to get real-time communication (or at least the appearance of it) between frontend and backend. What’s not clear to me is when exactly long polling would be used instead of websockets. I can’t find anything in the docs that spells it out.

Does the long-polling functionality exist as a fallback in case websockets don’t work or are unavailable for some reason? If so, under what circumstances would this happen?

Showing Posts 1 to 5

rhcarvalho

rhcarvalho

Yes, exactly. The fallback was added by default relatively recently, here you find more details:

At 00:00:58 Chris talks about long poll fallback.
(https://www.reddit.com/r/elixir/comments/16mi7qn/comment/k18nhjq/)

The client first tries to connect via WebSocket, and then ping the server to ensure the connection actually works.

If the WS doesn’t work for whatever reason, the client uses the fallback and saves a key to session storage (persistent until the browser is restarted) to go straight to the fallback in future page loads.

The circumstances are many, could be browser support, problems with network proxies messing up with WS messages, etc. Can also happen, many times during development, that the client is trying to connect while the server is down and then eventually sticks to the fallback long poll transport until the session is cleared.

LostKobrakai

LostKobrakai

There could also be clients which don‘t support connecting using websockets at all.

CharlesO

CharlesO

can this behavior be configured? I feel it hides the underlying issues that might be preventing WebSocket.

In case we need/want to investigate why WebSocket are not working in a given environment or for specific browser/OS configuration

rhcarvalho

rhcarvalho

Yes. At the limit you can have your own transports that “phone home” to give you insight.

AFAIK Chris’ experience at fly.io is that no matter how much they’d try to “fix” WS, there will always be cases out of control like proxies between users and the server.

stocks29

stocks29

I’ve been banging my head against the wall trying to figure out why I’m not even seeing the websocket connection attempted.

The session storage flag was the issue. Clearing the flag from session storage did the trick.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews