Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
socket.io on client side not listening to server events

The socket have to listen to the server when i send a new message.
The messages arrive because when i refresh the page i can see them.
Server side socket i know is working find because in other frontend app the same client socket is working find.
This socket is called every time the user select a new chat in the web.

Here is the socket service in my app:

import openSocket from "socket.io-client";

function connectToSocket() {
    return openSocket("http://localhost:8080");
}

export default connectToSocket;

And here is the code executed when user select a chat:

// how i am importing the socket
import openSocket from "../../Services/socket-io"

async function fetchMessages(ticketId) {
    try {
        const { data } = await api.get("/messages/" + ticketId, {
            params: { pageNumber },
        });

        if (ticketId === data.ticket.id) {
            await loadMessages(data, ticketId);
        }

        listenMessages(ticketId);

    } catch (err) {
        Toast.ToastError("Error trying to load messages");
    }
};

function listenMessages(ticketId) {
    const socket = openSocket();

    socket.on("connect", () => socket.emit("joinChatBox", ticketId));

    socket.on("appMessage", (data) => {
      if (data.action === "create") {       
        console.log(data);
      }

      if (data.action === "update") {
        console.log(data);
      }
    });
}

What i already tried:
Use the same socket version both in client and server (3.0.5).
Calling listenMessages every time a message is sent.
socket.io-client version 4.

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!