Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
Connect to a pyzmq websocket from JS

I'm creating a websocket from a python file with zmq.

server.py

context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
print ("socket created")
footage_socket.connect('tcp://192.168.1.15:1161')
print ("socket connected")
camera = cv2.VideoCapture(0)  # Init the camera

i = 0
while True:
    i += 1
    try:
        # print ("About to send ")
        # footage_socket.send(b"Hello ")
        # print ("Sent ")
        # time.sleep(1)
        # continue
        grabbed, frame = camera.read()  # Get the current frame
        frame = cv2.resize(frame, (640, 480))  # Resize the frame
        encoded, buffer = cv2.imencode('.jpg', frame)
        jpg_as_text = base64.b64encode(buffer)
        footage_socket.send(jpg_as_text)
        time.sleep(0.05)

    except KeyboardInterrupt:   # Stop the camera / stream
        camera.release()
        cv2.destroyAllWindows()
        break

I'm trying to connect to that Websocket with a js file :

Client.js

const { ipcRenderer } = require("electron");
var socket = new WebSocket('ws://192.168.1.15:1161')

document.addEventListener('DOMContentLoaded', (e) => {
    ipcRenderer.send('userInfo');
});


ipcRenderer.on('userInfo',(e,userInfo)=>{

        socket.onopen = function (data) {
            console.log(data + '_____________') 
          };

    });

but i get an error:

client.js:5 WebSocket connection to 'ws://192.168.1.15:1161/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

Can anybody explain me why ? and how to resolve ?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda