How do I make a Relay-Server with Node.js & Websocket

0 favourites
  • 6 posts
From the Asset Store
Create your own wss server and ws server with ssl and without ssl.
  • Heyho

    I could need some help with Javascript. I try to make a Relay-Server with Node.js & Websocket for my game with asynchrone multiplayer. Once i started with this project, i had very little knowledge about javascript and construct but im getting better. I made the same thing with the official multiplayer plugin provided by scirra, and it works reale good for a p2p dedicated server, but I would rather use the websocket plugin for various reasons. Could somebody explain me, how to code a Relay-Server with following functions?

    What the Server should do:

    • When the Client (right side) sends a message to the Relay-Server, the Server should relay the message to the Host (left side). After the Host processes the message, he should send a replay to this Client. The Client shouldn't send messages directly to other Clients.
    • The Relay-Server should have the ability to broadcast messages to all Clients

    What i already have done:

    • I already installed Node.js and downloaded the Websocket Library
    • I read the GitHub page of the Websocket Library
    • I watched some tutorials, but i didn't get it yet.

    What i need help with:

    Im learning reale fast and never had problems to find the right tutorials to improve myself, but im stuck und i need help with how to code these things.

    I would reale appreciate, if somebody could teach me.

    [EDIT:]

    So ... I now know, that I have to set an array on the Relay-Server and assign every user ,who connects, an unique ID to identify them ... the problem is, I don't know how. Would be nice, if the unique ID would be a 4 char ID like the one on the signaling server by scirra.

    So something like:

    Client sends encrypted Message to Server -> Server adds Unique ID and sends Message to Host

    Host sends encrypted Message with Unique ID to Server -> Server removes Unique ID and sends Message to that Client

  • *bump*

  • Hello,

    Sorry I can't help you for now but I will attempt something similar in a near future, maybe at some point we can trade tips. I just wondered what is the use of the relay server? Can't the host communicate with the clients directly?

    Thanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks, that would be awesome.

    In my Project, I made 2 games, one for the server and one for the client. The host is doing the whole work, the client is only sending requests and the host sends results back. I made this to prevent cheating. The Relay server just communicating with the host and all players.

    EDIT: I already made this with the official multiplayer plugin, but i don't want to rely on a signaling server.

  • Ok. So the game that is running on the host is used to process gamestate and logic and to validate that the clients don't do illegal moves? From what I understand the game on the host is not played by an actual person, it is only a resident app.

    When I get the right to send PMs I will send you one with my solution thus far. I don't use a relay server, but it might give you ideas.

  • This is exectly how it should work

    That would be realy awesome Thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)