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

153
Vistas
Streaming image/video with socket.io-stream and nodejs

I want to send a picture to the front using socket.io-stream but the browser does not enter the stream event .on('data' ) but enters the event .on('end')

why is that? and in addition - I want to finally add the code so that I can do live streaming of the video, just for now I'm trying to stream the image file

server

const express = require('express');
const { Server } = require("socket.io");
const http = require('http');
const fs = require('fs');

const app = express();
app.use(express.static("public"));
const server = http.createServer(app);
const io = new Server(server);
const ss = require('socket.io-stream');

app.get('/', (req, res) => {
  res.sendFile(__dirname + '/index.html');
});

// входящее сообщение, что клиент присоединился
// подхватываем сокет клиента
io.on('connection', (socket) => {
  console.log('user connect');

  setTimeout(() => {
    let ssStream = ss.createStream();
    ss(socket).emit('image', ssStream, 'log')
    fs.createReadStream('/Users/artem/Work/dataset/frame000023.png').pipe(ssStream);
  }, 1000)

 
})
server.listen(3000, () => {
  console.log('listening on *:3000');
});

client

const socket = io();

      ss(socket).on('image', function(stream,data) {
        console.log('received',data);

        var binaryString = "";

        stream.on('data', function(data) {
          console.log('data')

          for(var i=0;i<data.length;i++) {
            binaryString+=String.fromCharCode(data[i]);
          }

        });

        stream.on('end', function(data) {
          console.log('end')
       $("#img").attr("src","data:image/png;base64,"+window.btoa(binaryString));

          binaryString = "";
        });
      });
about 4 years ago · Santiago Gelvez
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