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

274
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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