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

236
Vistas
Socket Connection in Angular

i have a barcode printer i want to connect that printer using socket programming through my Angular project. the printer is on local network so i cant create socket from backend.i tried web socket and socket.io but i am not able to connect to the server.it gives connection failed. it immediatly goes to the error handling method.can some one help how can i create a socket connection using angular and send commands data to the printer

let connection = new WebSocket('wss://127.0.0.1:4000');

connection.onopen = function (e) {
  alert('[open] Connection established');
  alert('Sending to server');
  connection.send('data send');
  console.log(e, 'sendddddddddddddddddddddd');
  connection.onerror = function (error) {
    alert('Please check the server connection1: ' + error);
  };

  connection.onmessage = function (e) {
    console.log('onmessage');
    var respData = e.data;
    alert(respData);
  };

I also tried XHR but same thing happend it only goes to error

let captureUrl = 'wss://javascript.info/article/websocket/chat/ws';

 const xhr = new XMLHttpRequest();
 xhr.open('POST', captureUrl);
 console.log(xhr);

 xhr.responseType = 'json';
   xhr.setRequestHeader('Content-Type', 'application/json');
 const reqParam: any = {
   command: 'STAR',
   startpage: 'startPages',
   endpage: 'endpage',
 };
 const reqParam: any = { command: 'DATA', data: 'none' };
 var res = await xhr.send(JSON.stringify(reqParam));
 console.log(res, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaa');

console.log(xhr.readyState);

xhr.onload = function () {
  
   alert('onmload');
 };

 xhr.onerror = function () {
    only triggers if the request couldn't be made at all
  alert('Network Error');
 };
about 4 years ago · Juan Pablo Isaza
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