0 Favourites

How to identify players using websocket?

  • I'm using the websocket-plugin i C2, and I'm learning myself to program node.js servers. I am able to connect to the server and send and receive messages. I have made a "game" that counts clicks on a button, but if I open it on my PC and phone, changes only happens on the device where the action is done. Do I have to identify each device or something? And/or is there a way to broadcast it to every client connected? Any help would be appreciated.

    Here's my server script so far:

    var WebSocketServer = require('ws').Server
      , wss = new WebSocketServer({ port: 8080 });
    
    var total = 0;
    
    wss.on('connection', function connection(ws) {
      ws.on('message', function incoming(message) {
    	total += 1;
        console.log('received: %s, total=' + total, message);
        ws.send(total);
      });
    });[/code:tocpixrl]
  • Omg, they added a web socket wrapper, yay! Thanks Ashley!

    And to answer your question, yes, every client should have an independent ID managed by the signalling server (I think). Once I have a working test client, I will be able to answer your other questions.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You need to implement everything you described yourself, by sending messages over the WebSocket connection. When you add in the synchronisation issues (since everyone has a different latency, so is working on a different delay to the "real" game) it becomes extremely complicated. The Multiplayer object has already solved all of this for you!

  • You need to implement everything you described yourself, by sending messages over the WebSocket connection. When you add in the synchronisation issues (since everyone has a different latency, so is working on a different delay to the "real" game) it becomes extremely complicated. The Multiplayer object has already solved all of this for you!

    Yeah, I figured out that the Multiplayer object was way easier, and made me not having to walk through a bunch of trial and error.

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