Azolo

Azolo

Hey everyone,

I just released WebSockex which is a Elixir WebSocket client.

WebSockex strives to work as a OTP special process, be RFC6455 compliant, and be simple to use by providing smart defaults for common actions.

Take a look and let me know about any questions, suggestions, or any other comments you may have,

Showing Posts 43 to 34

idi527

idi527

The thing that I don’t know about is checking to see if iodata is valid UTF8 for text frames. Currently I’m using String.valid?/1. If I remember correctly it doesn’t work with iodata. If it does, then I am totally wrong and there is no problem at all.

Oh, I haven’t thought about it. Is this check required by the spec?

If it is, something like cowlib/src/cow_ws.erl at master · ninenines/cowlib · GitHub can be adapted to work with iodata.

The validation in cowboy though happens only on the receiving end, it seems.

Azolo

Azolo OP

Honestly, it probably is easier to use IO.iodata_length. Feel free to open an issue or PR.

The thing that I don’t know about is checking to see if iodata is valid UTF8 for text frames. Currently I’m using String.valid?/1. If I remember correctly it doesn’t work with iodata. If it does, then I am totally wrong and there is no problem at all.

idi527

idi527

It seems like websockex doesn’t support iodata in send_frame?

** (exit) exited in: WebSockex.call(Some.Client, {:text, ["{\"cmd\":", [34, [], "keepalive", 34], ",\"session_id\":", [34, [], 34], ",\"transaction\":", [34, [], "y653PDXvxmGaW+0y4Nab", 34], 125]})
    ** (EXIT) an exception was raised:
        ** (ArgumentError) argument error
            :erlang.byte_size(["{\"cmd\":", [34, [], "keepalive", 34], ",\"session_id\":", [34, [], 34], ",\"transaction\":", [34, [], "y653PDXvxmGaW+0y4Nab", 34], 125])
            (websockex) lib/websockex/frame.ex:296: WebSockex.Frame.get_payload_length_bin/1
            (websockex) lib/websockex/frame.ex:257: WebSockex.Frame.encode_frame/1
            (websockex) lib/websockex.ex:723: WebSockex.sync_send/5
            (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
    (websockex) lib/websockex.ex:349: WebSockex.send_frame/2

Wouldn’t it be easier to use IO.iodata_length instead of :erlang.byte_size? Since it works both on binaries and iolists.

iex(8)> data = API.Keepalive.new() |> Jason.encode_to_iodata!() |> IO.iodata_length()
74
iex(9)> data = API.Keepalive.new() |> Jason.encode!() |> IO.iodata_length()
74
idi527

idi527

Hi @Azolo!

I wonder if it’s possible to use WebSockex with subprotocols? I can’t seem to find any mention of it neither in the docs nor in code …

EDIT:

WebSockex.start_link(url, __MODULE__, state, [
  name: __MODULE__, extra_headers: [{"Sec-WebSocket-Protocol", "my-protocol"}]
])

seems to work fine.

gordoneliel

gordoneliel

How were you able to connect to the socket.io client? Do you have any sample code?

NobbZ

NobbZ

Ulimit does only increase the softlimit which can never be higher than the hard limit. The hardlimit needs to be increased first, on most systems you can do so via sysctl AFAIR.

Im in mobile so it’s hard to do a proper check right now.

indera

indera

@Azolo thank you for the prompt response… I increased the number of “open files” to 200K but still no luck.
I changed the code to display a specific error in
websockex/websockex/conn.ex

 91   @spec socket_send(__MODULE__.t, binary) :: :ok | {:error, reason :: term}
 92   def socket_send(conn, message) do
 93     case conn.conn_mod.send(conn.socket, message) do
 94       :ok -> :ok
 95       {:error, error} -> {:error, %WebSockex.ConnError{original: "ERR_A"}}
 96     end
 97   end

so it looks like this is triggered in a “SEND”.
How would you recommend to debug the

“conn.conn_mod.send(conn.socket, message)” call?

===== Fragment of code which you can test

  5   def start(server, users) do
  6     all_users = 1..users
  7
  8     Logger.info("Simulator: registering #{users} users...")
  9     all_users
 10     |> Enum.map(fn i ->
 11       Task.async(fn ->
 12         {:ok, client} = WebSockex.start_link("ws://0.0.0.0:4000/socket/websocket", [])

 15       end)
 16     end)
 17     |> Enum.each(&Task.await/1)
Azolo

Azolo OP

I would guess that is probably an OS file descriptor limit, but other than that I don’t know.

Mt best guess would be to try increasing the maximum file descriptors on the server and client using ulimit -n.

indera

indera

@Azolo Is there a OS configuration necessary to be able to create 1K websockets connecting to the same Phoenix instance. I am getting this error

(MatchError) no match of right hand side value:

{:error, %WebSockex.ConnError{original: :closed}}

after about 200 processes created with this code

opts = [

  {:debug, [:trace]},
  {:socket_connect_timeout, Keyword.get(
    opts, :socket_connect_timeout, @socket_connect_timeout)},
  {:socket_recv_timeout, Keyword.get(
      opts, :socket_recv_timeout, @socket_recv_timeout)},
]

    WebSockex.start_link(conn_info, __MODULE__, state, [ {:debug, [:trace]} | opts] )
Azolo

Azolo OP

Hopefully anytime that the process is going to exit for whatever reason.

If there is a time that terminate isn’t called then it is considered a bug.

Where Next? Top

Trending in Announcing Top

type1fool
WebAuthnLiveComponent WebAuthnComponents See this post about renaming the package. Passwordless authentication for Phoenix LiveView app...
New
GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. https://github.com/woylie/doggo Features Unstyled Phoenix components....
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
kip
I’ll shortly be launching Text, a nascent text analysis library. Current functionality In this early version (not ready for prime time) ...
New
kip
Following on from my CLDR lbraries I started work on Unicode transforms. But like everything related to CLDR there is a lot of yak-shavin...
New

Other Trending Topics Top

budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
Null-logic-0
What IDE or editor are you using for Elixir development? Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews