1.16.5 SocketIO Help

Discussion in 'Spigot Plugin Development' started by Preodym, Jun 16, 2021.

  1. Hello,

    I wanted to create a connection between website and plugin with SocketIO. The website should know where the player is and do something.

    The Maven dependency doesn't work either. The SocketIO server already exists.

    does someone have all the necessary information for me?

    Somehow it doesn't work for me. Does anyone have code snippets? I need a little help.

  2. Hey, I really feel your pain. I had similar issues with socketio in Java because the library is not really well maintained. I used a websocket library instead and that should work better.

    If you need some code examples, you could use this Projekt that I coded and check how I implemented websocket client side. The server was socketio in nodejs

  3. Thank you! It's finally connecting! Sending just a message doesn't work. How did you solve that?
    • Like Like x 1
  4. Hey,

    you would use the
    Code (Java):
    WebSocketClient#send(String message)
    method to send messages.
    Because socketio follows some protocol you need to watch the messages in the browser dev tools.

    As example with sending
    You would need to append 42 at the front of the message that you sent, that should than work as expected.
  5. i habe this
    Code (Text):
    socket.send("42{hi:HELLO TEST}");
    but nothing happens

    don't I have to name a "channel" somewhere?
  6. I've been trying it all day.

    With onEnable () I connect the WebSocket.
    in the JoinEvent I use Main.socket.onMessage ("42 [location," + jsonarray + "]"):

    Why doesn't the server get anything? But when it comes to connect, what matters.

    Thank you!
  7. You could use the dev tools. Open your website and press alt, ctrl and J and under network you can serach for the socketio connection. When you click on it, you see messages and check how they sent.

  8. If I understood what OP've said correctly, the OP's issue is about the connection between the website (based on whatever backend) and the plugin, not a browser and the backend. I am not sure this would be useful if there isn't a way for DevTools to inject itself into a connection intermediately.

    When I dealt with Socket.IO the issues are usually because:
    • Socket.IO server did not have a proper mounted endpoint if you mount Socket.IO on another server object
    • Server/Client are emitting on different channels
    • Server/Client are using different transports
  9. I would like to send information about a player

    music is playing on the website - and depending on where you are in the world, different ones should be played.