code
Are there any libraries that can help me build a WebSocket client?
Hello.
I am looking for a library that will help me build a WebSocket client, I’ve found WebSockex but it seems to be abandoned. I just want to build a client that sends and receive information from a server. Any recommendations are appreciated.
Most Liked
al2o3cr
Hard to say what’s happening without a stack trace.
I tried your code and it works:
defmodule WsClient do
use WebSockex
def start_link do
WebSockex.start_link("wss://fstream.binance.com/ws/bnbusdt@aggTrade", __MODULE__, nil)
end
def handle_frame({type, msg}, state) do
IO.puts "Received Message - Type: #{inspect type} -- Message: #{inspect msg}"
{:ok, state}
end
end
Result:
iex(4)> WsClient.start_link()
{:ok, #PID<0.224.0>}
Received Message - Type: :text -- Message: "{\"e\":\"aggTrade\",\"E\":1721436649844,\"a\":585965926,\"s\":\"BNBUSDT\",\"p\":\"592.070\",\"q\":\"0.01\",\"f\":1345576048,\"l\":1345576048,\"T\":1721436649691,\"m\":true}"
Received Message - Type: :text -- Message: "{\"e\":\"aggTrade\",\"E\":1721436650734,\"a\":585965927,\"s\":\"BNBUSDT\",\"p\":\"592.080\",\"q\":\"3.92\",\"f\":1345576049,\"l\":1345576064,\"T\":1721436650579,\"m\":false}"
Received Message - Type: :text -- Message: "{\"e\":\"aggTrade\",\"E\":1721436651055,\"a\":585965928,\"s\":\"BNBUSDT\",\"p\":\"592.090\",\"q\":\"0.03\",\"f\":1345576065,\"l\":1345576065,\"T\":1721436650901,\"m\":true}"
Received Message - Type: :text -- Message: "{\"e\":\"aggTrade\",\"E\":1721436652573,\"a\":585965929,\"s\":\"BNBUSDT\",\"p\":\"592.090\",\"q\":\"0.19\",\"f\":1345576066,\"l\":1345576067,\"T\":1721436652419,\"m\":true}"
On a machine with an older Elixir (1.13), in case that makes a difference.
al2o3cr
use isn’t directly comparable to “imports” in other languages (after all, there’s import/2 already
) - it generates code into the module that calls it.
HTTPoison supports two different styles of interaction: plain functions (HTTPoison.get etc) and “wrapping”. Wrapping can be useful when you need to make many similar-shaped requests.
Websockex doesn’t support the plain function approach at all.
janp
Have a look at GitHub - mtrudel/bandit: Bandit is a pure Elixir HTTP server for Plug & WebSock applications ![]()
Edit: Ooops, you asked for a client… Bandit is a server.
For my last websocket client I used WebSockex.







