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

129
Views
Socket.io: client.on responds to messages for other clients

so i'm having a problem with Socket.io:

So in the server i'm sending a message to the client like that:

Note that the snippets below are just simplifications of what i'm doing

import { Server, Socket } from 'socket.io';

const app = express();
const http = require('http');
const server = http.createServer(app);
const io = new Server(server, { cors: { origin: '*' } });

io.on('connection', socket => {
  socket.on('message', (data) => {
    // ... some computation here
    socket.emit('other message', computeddata); // Should only send to the 
  sender
  });
});

And on the client im receiving it like that:

socket.on('connect', () => {
  socket.emit('message');
});

socket.on('other message', (data) => {
  console.log(data);
});

When the server emits the message to the socket, it should only send to the specific socket right? Well, ALL the connected sockets pick up on it.

How can I make it so that the message only sends to the sender?

I'm a bit new to socket.io, Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

i managed to fix the issue, there was a io.emit line that I somehow missed 3 times, that ruined the rest of the emits. Oh god.....

about 4 years ago · Juan Pablo Isaza Report
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!