code

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

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

al2o3cr

use isn’t directly comparable to “imports” in other languages (after all, there’s import/2 already :stuck_out_tongue: ) - 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

janp

Have a look at GitHub - mtrudel/bandit: Bandit is a pure Elixir HTTP server for Plug & WebSock applications :slight_smile:

Edit: Ooops, you asked for a client… Bandit is a server.


For my last websocket client I used WebSockex.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
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
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
jc00ke
Expanding on this topic: https://forum.elixirforum.net/t/map-typespec-question/19217 Let’s say I have a map with required and optional k...
New

Other popular topics Top

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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement