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

268
Vistas
Sending bytes from javascript client to java backend DatagramSocket

I have a java app that functions as a server, listening to some port using the java.net.DatagramSocket class. The server is able to receive packets from some other java clients. What I did not manage to do is have a javascript client to the server. I've tried sending messages as WebSocket client

    const ws = new WebSocket("ws://localhost:9999");
    ws.addEventListener("open", () => {
        console.log("CONNECTED")
    })

But I'm getting the following error in the browser console:

App.js:9 WebSocket connection to 'ws://localhost:9999/' failed:

I've also tried using net library to send message:

    const net = require("net");
    const options = {
        post: 9999
    };
    const  client = net.createConnection(options);
    client.write("TEST")

But I'm getting the following error:

Uncaught TypeError: net.createConnection is not a function

Is there any other way to do this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

UDP (DatagramSocket) and WebSocket are totally different things. WebSocket is a protocol on top of HTTP which is on top of TCP.

In JavaScript running inside the browser you cannot send UDP packages.

You can write some kind of a proxy server, which can receive messages via WebSocket from your JavaScript program and send them via UDP to your server.

Or extend your server with a WebSocket interface.

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