CAIOHOBORGHI

CAIOHOBORGHI

Hello guys, how are you?

I’m trying to connect to a local socket.io server using WebSockex but when the application tries to run

WebSockex.start_link("ws://socket:8007", __MODULE__, state)

it always throws the error

** (EXIT) %WebSockex.ConnError{original: :closed}

The problem is that the server isn’t closed… I used docker-compose to run a server and a client container and with node it works.

Thats my server.js file:

const http = require("http").createServer();
const io = require("socket.io")(http);
const port = 8007;

var connectedClients = [];

http.listen(port, "0.0.0.0", async () => {
  console.log("server listening on port:" + port);
});

io.on("connection", async (socket) => {
  connectedClients.push(socket.id);
  socket.on("message", async (body) => {
    socket.broadcast
      .to(socket.id)
      .emit("message", "Message sent successfully!");

    var command = JSON.parse(body);
    if (command.action == "add_alert") {
      io.emit("add_alert", command);
    } else {
      io.emit("add_alert", "error receiving alert!");
    }
  });
});

Thats my client.js file

const io = require("socket.io-client");

const socket = io.connect("ws://socket:8007");
socket.on("connect", () => {
  var obj =
    '{"action":"add_alert","data":{"user":{"id":1231298301283,"name":"Caio Borghi","phone":"+55900000000","alerts":[{"id":"hashID1","code":"ELET6","field":"Close","comparison":"<=","value":11.9,"message":"ELET6 Close price is lower than 11.9!"},{"id":"hashID2","code":"BBDC4","field":"Close","comparison":"<=","value":15.9,"message":"BBDC4 Close price is lower than 15.9!"}]}}}';
  socket.emit("message", obj);
  console.log("Client is Listening the Local connection.");
});

socket.on("add_alert", async (body) => {
  console.log("Alert received: " + JSON.stringify(body));
});

And in my docker-compose i`m connecting all 3 containers in the same network…

The big deal here is that the client container works perfectly pointing to the same URL that my Elixir application (ws://socket:8007) but when I try to connect through Elixir, it never works.

Do you know if there`s any config I need to change to be able to connect to “local” websockets with WebSockex? Or any tip of what I should try to make it work?

Thanks in advance, any help is welcome!

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews