Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
Convert socket.io Javascript code to python-socketio

I have a javascript using socket.io.
I would like to convert this javascript file to python:

io.on('connection',(socket)=>{
    
    let nsData = namespaces.map((ns)=>{
        return {
            img: ns.image,
            endpoint: ns.endpoint
        }
    })
    // console.log(nsData)
    socket.emit('nsList',nsData);
})

This is what I have in python:

@sio.event
def connect(socket_id, environ):
    # ???
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

On the documentation, it is stated that you just need to either use a return statement or use the .emit() function. https://python-socketio.readthedocs.io/en/latest/server.html#emitting-events As the docs say, you simply need to

sio.emit('nsList', nsData, room=socket_id)

That will emit the nsList event with the content nsData. However, I do not know what nsData is. It seems to simply be a map statement, which can be done with the map() function. As GFG states, you simply need to map out the namespaces. https://www.geeksforgeeks.org/python-map-function/ Assuming namespaces is a list, you can do something similar to this:

def mapNsData(ns):
    return { 'img': ns.image, 'endpoint': ns.endpoint }

Then, use the map function:

nsData = list(map(mapNsData, namespaces))

Tada! Now, you have a list to send to the client!

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda