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

168
Visualizações
Javascript websocket not connecting

I'm trying to make a simple chat application

I have a server made with Spring running with a websocket

I've also made an android app that successfully connects to the websocket and receives and sends messages

To make testing easier I decided to make a web client for the server in html/js, but the websocket connection fails

I'm using the exact same address as I am in the android app

Heres my JS code:

$( document ). ready(function(){

    var ws = new WebSocket("ws://192.168.1.3:8080/chatwebsocket")

    ws.onmessage = function (event) {
        var msg = event.data
        $("#chat_container").append(`<p>$(msg.sender): $(msg.content))</p>`)
    }

    ws.onerror =  function (event) {
        console.log('WebSocket error: ', event);
    }

    ws.onclose = function (event) {
        console.log('WebSocket closed: ', event);
    }


    $("#message_form").onsubmit = function(data) {
        var msgContent = data.messageContent
        var msg = {"sender":"webclient", "content": msgContent}
        ws.send(JSON.stringify(msg))
    }
})

I've tested it with Chrome and Firefox and both fail Chrome just gives the message: WebSocket connection to 'ws://192.168.1.3:8080/chatwebsocket' failed:

Theres no useful info in either the error or close events

No connection is made on the server side

The web client successfully connects to wss://ws.postman-echo.com/raw for an example

Can someone please point me in the right direction with troubleshooting this because I feel like I have no info to work with

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