websocket server inside c2 (stable multiplayer idea) !

0 favourites
  • 3 posts
From the Asset Store
94 Inside buildings views - Isometric view - PNG transparent - 2048x2048
  • hi since multiplayer is not stable (users mostly disconnected) its might be good for small games but no good for big games.

    i have an idea which we can make a multiplayer with websocket and don't need to js programming !!!

    this is what we need :

    1 - nodejs server script

    2 - server side game

    3 - client side game

    so we need to make a node js to pass the all client messages to the host and pass host messages to a specific client !

    like this :

    all clients >> node js server >> server game (we can run node js and server game in single host so the latency is 0)

    game server >> node js server (get client username from the server message and send message to that user) >> a specific client

    client message type is : (c$tag$username$data)

    server message type is : (s$tag$username$data)

    i will say why we have this type of messages !

    so we need a node server to do that and i wanted to use ws module for nodejs but it doesn't respond sometimes !!

    this is my code for ws server :

    in my code server split messages and if "c" so this message from client and if "s" then its a server

    "tag" is like tag in multiplayer plugin

    "username" is client username (even in server messages)

    so in server game and client game we can split messages with tokenat and then use them !

    so anyone can help ?

    var WebSocketServer = require('ws').Server, wss = new WebSocketServer({port: 1337});
    var connections = {};
    wss.on('connection', function(ws) {
        ws.on('message', function(message,ws) {
            console.log('received: %s', message);
            
            var res = message.split("$");
            if(res[0] == "s")
            {
                ws.send(message);
                
                    if(res[1] == "login")
                    {
                        connections["server"] = ws;
                    }
                    else
                    {
                        ws.send(message);
                        if(connections["client"])
                        {
                            connections[res[2]].send(res[1] + res[3]);
                        }
                    }
                    
            }
            else
            {
                    if(res[1] == "login")
                    {
                        connections[res[2]] = ws;
                    }
                    else
                    {
                        connections["server"].send(res[1] + res[2] + res[3]);
                    }
            }
    
        });
        
    });
    [/code:2ebh4j8g]
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • As far as I am aware Multiplayer is stable - people getting disconnected is probably due to network connectivity issues over the Internet itself, which would affect any technology you use to connect.

    WebSocket is also limited to TCP transport which can make it perform poorly over unreliable connections.

  • As far as I am aware Multiplayer is stable - people getting disconnected is probably due to network connectivity issues over the Internet itself, which would affect any technology you use to connect.

    WebSocket is also limited to TCP transport which can make it perform poorly over unreliable connections.

    in this line you just said multiplayer is not stable ! yes internet have problem and users get disconnected but this problem is for a few second and in multiplayer plugin you must try to reconnect them to each other fast and if this few second get bigger then you must disconnect them !

    but in multiplayer plugin when they disconnect for just a second plugin disconnect them and doesn't try to reconnect them fast and we can not reconnect them fast because we must connect to your server and then login and then join room and then connect to game and this process take so much time for us .

    but in websocket we can connect them fast again !

    and due to this bug :

    scirra.com/forum/viewtopic.php?f=146&t=150590

    if host get disconnected from signalling server it does not know that sometimes !!!

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