How to identify players using websocket?

Get help using Construct 2

Post » Sat Jan 30, 2016 2:32 am

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:

Code: Select all
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);
  });
});
Image
B
14
S
4
Posts: 145
Reputation: 1,943

Post » Sat Jan 30, 2016 4:37 pm

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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,365
Reputation: 4,724

Post » Mon Feb 01, 2016 12:13 pm

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!
Scirra Founder
B
383
S
225
G
86
Posts: 24,118
Reputation: 190,544

Post » Sat Feb 06, 2016 12:57 am

Ashley wrote: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.
Image
B
14
S
4
Posts: 145
Reputation: 1,943


Return to How do I....?

Who is online

Users browsing this forum: ankas and 10 guests