shahryarjb
How to Keep the connection alive in phoenix socket for mobile app
Hello, I want to create a socket api for mobile app and I test it with wscat libe in terminal, but after seconds it shows me a Disconnected (code: 1000) and it is closed if I don’t push anything to client.
how can I keep it alive in phoenix socket client (terminal), for example I should push a massage like string “ping” to my client?
➜ wscat -c 'ws://localhost:4000/socket/websocket?vsn=2.0.0'
Thanks
Most Liked
l00ker
There are 3rd party Phoenix client libraries available:
- Swift (iOS)
- Java (Android)
- C#
- Elixir
- GDScript (Godot Game Engine)
Maybe one of these will be of use.
NobbZ
No, just a proper client for the channel. wscat just connects on a websocket and you need to talk raw. If you never send a heartbeat, the phoenix will eventually disconnect you, depending on the timout settings.
PragTob
Little word of caution - implementing a client might not be as easy. I was working with a very competent android developer and the channel implementation was a constant source of bugs and problems. Especially if the app is sometimes supposed to sleep keeping the connection alive around OS energy optimization can be pretty rough.
I’ll never forget the joy in the devs eyes when we switched to a simple REST API instead of channels
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









