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

370
Views
What is difference between socket.on and io.on?

Server side code:

io.on('connection',(socket)=>{
    console.log('New WEBSocket Connection')

 
    socket.emit('message',"welcome")
    socket.broadcast.emit('message',"A new user joined")

    socket.on('textMessage',(message,callback)=>{

        const filter = new Filter();
        if(filter.isProfane(message)){
            return callback('Mind your languezz')
        }

        io.emit('message',message)
        callback()
    })
}

Client side code:

socket.emit('textMessage',message,(error)=>{
        if(error){
            return console.log(error)

        }
        console.log("Message Delivered")
    })

My doubt is, on client side code, what if I used io.on instead of socket.on? socket.on('textMessage',(message,callback)=>{............instead I did it like this: io.on('textMessage',(message,callback)=>{.............

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

0

io.on listens to the server events. connection is an event on the server, when a socket is connected. And when that socket is connected, the callback function inside that is run.

socket.on listens to events on that connected socket. socket.on('textMessage' asks to do something when textMessage event is emitted on the socket, which you do from your client using socket.emit('textMessage'

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!