WalkPhoneGo
Can Phoenix channel detect client offline immediately?Like WiFi disconnected
I need to know whether the client is online, when WiFi is down.
The server should know it immediately. Can anyone tell me an elegant solution?
Now as I tested, Phoenix Channel needs about 40-50s to detect the client is disconnected.
Marked As Solved
chrismccord
You need to also set the webserver’s idle timeout to a lower value, ie
config :app, AppWeb.Endpoint,
http: [
...,
protocol_options: [
idle_timeout: 10_000
]
]
Also Liked
NobbZ
An instant event in this case is technically impossible.
Only the client knows about the cut down WiFi. But since WiFi is down, it can’t tell the server.
There might even be situations in which neither of the participants know about the disconnect. Lets say your ISP drops the connection. Neither your client nor your server will know this until they try the next heartbeat and it times out.
This is just how networking works.
sb8244
Hey @acrolink, I got your example figured out (feel free to post the example here, it may be useful for others?)
In the code example you sent, the idle_timeout was set at the cowboy HTTP config level. Run :ranch.get_protocol_options(MemeWeb.Endpoint.HTTP) to see what I mean. By default (no protocol options set), you won’t see idle_timeout in the HTTP endpoint. If you specify the idle timeout, then you’ll see it from that command.
However, cowboy_websocket uses a separate mechanism than the HTTP idle_timeout for it. You can see the option specified at https://ninenines.eu/docs/en/cowboy/2.2/manual/cowboy_websocket/. Phoenix sets up the cowboy_websocket opts at this line of code, and you have to specify it in the format timeout: X.
In your app, that is done with:
socket("/socket", MemeWeb.UserSocket,
websocket: [
timeout: 10_000
]
)
This code was commented out in the repo you sent me. I added it back in, set it to 10k, and I reliably detected failure within 10 seconds using your reproduction steps.
tl;dr the timeout option must be set in the socket options, and the UI must specify the heartbeatIntervalMs to a time lower than that. A value of 10_000 (socket) and 5_000 (client) will detect failure within 10 seconds.
WalkPhoneGo
Yes!!!, that’s what I need. work like a charm!!!!!!
Thank you!
I was fed up with the Actionable so I chose Phoenix Channel,it’s like magic!!!
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









