How do I make sockets work?

0 favourites
  • 6 posts
From the Asset Store
_______ Huge collection of metal fixtures ________
  • Hello,

    I followed this tutorial youtube.com/watch

    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.

  • Firstly see this from the websocket manual:

    [quote:32v3bb8y]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.

  • This is the script file

    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');
    });[/code:1c26tu5x]
    
    I want the blue player to move on the left screen too. The other player is not showing.
    i.imgur.com/PsZeoLK.png
  • Firstly see this from the websocket manual:

    [quote:3p3a3o3j]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?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So you'd probably want something like this:

    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);
      	});
      });
    });
    [/code:g5m4lmuo]
  • Yeah! It works!

    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?

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