[HTML/Javascript] Websocket closes immediately

Discussion in 'Spigot Plugin Development' started by The_Red_Freak, Jun 6, 2017.

  1. Hello,

    I want to program a simple Webinterface which shows the chat, the playerlist, and customizable Youtube playlist.
    But the Websocket connection from the interface to the server closes immediately.



    Thanks in advance!
  2. Are you sure there is no program using that port?
  3. Does the server start properly, is there any error being thrown, and does the connection even reach your server / does it even initialise a connection?
  4. First it connects and after it receives a Message from the Server it closes the connection
  5. Nope just the Server.

    I don't want to use Spark.

    Yes it does.

    Btw sorry for not answering the last days
  6. Hey! I've ventured into the hole of websocket and I never returned. I get high on the idea of connecting server functionality with websites :p
    Aside from that, I'm struggling to understand what you mean. Do you have any suspicions of which side the connection isn't being made on? Are you sure the javascript is working as intended? If yes, how about the server? Which side do you think is having an issue? Is there any sign at all of any communication occurring?

    I threw quite a few questions in there. At least, with them answered, we may be able to help you more easily.
  7. Open the developer console on chrome for your page - You'll find a console which logs everything - very useful if things are going wrong (you probably knew this but meh).
    Code (Text):
    setInterval(function () {
            console.log("" + s.readyState)
        }, 100);
    I lack a lot of theory knowledge for JS, but you missed a semicolon at the end of the center line - that may throw things off.
  8. Found another line missing a semi-colon:
    Code (Text):
  9. Hey,
    thanks for responding quickly! I tried it with the missing semicolon, still closes connection when it receives a message from the server.
    (For development reasons i coded a extra Websocketserver in which i can manually send commands to connected sites, if thats interesting for you :D)
  10. I added
    Code (Text):
    if(this.s instanceof WebSocket){
        s = null;
    which works, i don't know why i need to add this, but yeah...


    I just noticed when i send [PLR]Player1,Player2,Player3 to the websocket it closes the connection