How do I make sockets work?

Get help using Construct 2

Post » Thu May 26, 2016 10:18 pm

Message: GSquadron can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
Hello,
I followed this tutorial https://www.youtube.com/watch?v=YiTPVBnf8Es
The problem is that I have a localhost instead of scribble.
It does work cuz I see it from the cmd, but the problem is I have no idea what I have to do to manipulate the javascript file so it sends data to the browser.
Right now it does not work as it is intended. It just reads and sends data, but the game does not show simultaneously.
How can I make it multiuser?

Here are my 2 cents.
Image
B
25
S
7
G
1
Posts: 200
Reputation: 2,530

Post » Thu May 26, 2016 10:30 pm

Firstly see this from the websocket manual:

WebSockets and multiplayer games
It may be tempting to use WebSockets to design real-time multiplayer games. Unfortunately, despite the fact they communicate in real-time, WebSockets are not currently a suitable choice for this. The underlying transport uses reliable transmission, meaning a single dropped packet can hold up all transmission until the packet is retransmitted successfully. For games with demanding real-time requirements, this can cause unplayable levels of latency. It is usually impossible to design around this without changing the transmission mode, which WebSockets do not support.

On the other hand, WebSockets should be suitable for games without such a demanding real-time requirement, like turn-based games. It should also be useful for application services, like chat rooms. Note this will still require you to create your own WebSocket server.


You are trying to make player 2 shadow player 1? This event sheet looks correct for that. When you receive a message, append it to the output also, see if you are getting messages back, if not then there's a problem with your server script and you'd need to post that for us to be able to help further.
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Fri May 27, 2016 7:18 am

This is the script file
Code: Select all
var WebSocketServer = require('ws').Server
  , wss = new WebSocketServer({ port: 8080 });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
    console.log('received: %s', message);
  });

  ws.send('something');
});


I want the blue player to move on the left screen too. The other player is not showing.
i.imgur.com/PsZeoLK.png
B
25
S
7
G
1
Posts: 200
Reputation: 2,530

Post » Fri May 27, 2016 3:56 pm

briggybros wrote:Firstly see this from the websocket manual:

WebSockets and multiplayer games
It may be tempting to use WebSockets to design real-time multiplayer games. Unfortunately, despite the fact they communicate in real-time, WebSockets are not currently a suitable choice for this. The underlying transport uses reliable transmission, meaning a single dropped packet can hold up all transmission until the packet is retransmitted successfully. For games with demanding real-time requirements, this can cause unplayable levels of latency. It is usually impossible to design around this without changing the transmission mode, which WebSockets do not support.

On the other hand, WebSockets should be suitable for games without such a demanding real-time requirement, like turn-based games. It should also be useful for application services, like chat rooms. Note this will still require you to create your own WebSocket server.


You are trying to make player 2 shadow player 1? This event sheet looks correct for that. When you receive a message, append it to the output also, see if you are getting messages back, if not then there's a problem with your server script and you'd need to post that for us to be able to help further.


Hey man, I have searched all around the internet and cannot find a solution to this.
Can someone help in any way? I really would love to make it come to reality.
What about the multiplayer option? How can I make the cubes move for two players?
B
25
S
7
G
1
Posts: 200
Reputation: 2,530

Post » Sat May 28, 2016 2:11 pm

So you'd probably want something like this:

Code: Select all
var WebSocketServer = require('ws').Server, wss = new WebSocketServer({ port: 8080 });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
    console.log('received: %s', message);
   
   wss.clients.forEach(function each(client) {
       client.send(message);
     });
  });
});
Nothing goes unanswered!
B
24
S
5
G
1
Posts: 434
Reputation: 3,446

Post » Sun May 29, 2016 2:09 pm

Yeah! It works! :D
One last thing though.
The problem is that the red squares now get randomized differently for each screen.
(Which is Spawner spawn blocks on layer 1)
How do I do it so that the red squares (blocks family) get randomized the exact same on both screens of the players?

Also, I did not understand the code to tell the truth.
What do I need to read to understand it? Node.js?
B
25
S
7
G
1
Posts: 200
Reputation: 2,530


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, evillair, gamecorpstudio, jorgmaquoi, ultrafop and 24 guests