0 Favourites

[Socket.io] Players coordinates

  • I created a little project in which I have 2 players.

    Every tick Im asking server for the second player's coordinates and      

    along with this sending him mine.

    Everything works fine for the first 10-15 second. Then it began to lag and then it freezes.

    Can you tell me any other way how to optimise exchange of coordinates?

  • Every tick = 0,001 seconds or less... so the lag begins with huge amount of data been received.

    Instead, use every 0,05 seconds.

    Sometimes unfocusing the window in each the game is playing can also lag the communication.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Vladoss

  • Instead, use every 0,05 seconds.

    Are you sure this will help?

    What about 0,1?

  • Get it tested and see for yourself.

  • Get it tested and see for yourself.

    It still did not helped. Maybe there is a problem with my code?

    <img src="https://dl.dropboxusercontent.com/u/34384736/construct/socket.png" border="0" />

  • You are sending 3 times every 0,01 seconds and that's too much. You don't even need it. Get one 'Send' with all the data that you wanna out.

    You should send this kind of data about every 0,02 seconds max.

    What about a sprite for your player and other for online players? It would help removing that first pick from your code and the 8direction "is moving?", also. You would be able to use the clean:

    Every 0,05 seconds:>Send ("alldata," & "," & id & "," & x & "," & y)

    The second part, the one about managing received data, looks just fine.

    By the way, what language do you speak? Are you deep into socket.io? I have problems myself about hosting it. Could you help me?

    Vladoss

  • Every 0,05 seconds:>Send ("alldata," & "," & id & "," & x & "," & y)

    For the server part or a client? I'm a little misunderstood.

    If I will send some kind of data to the server, how can I split it?

    By the way, what language do you speak? Are you deep into socket.io? I have problems myself about hosting it. Could you help me?

    My native language is Russian, but I can uderstand English well enough and write it clearly enough :)

    If you need help add me on Skype: ivladoss

  • >

    > Every 0,05 seconds:>Send ("alldata," & "," & id & "," & x & "," & y)

    >

    For the server part or a client? I'm a little misunderstood.

    If I will send some kind of data to the server, how can I split it

    Your client. You gonna delete the pick, the "is moving?" condition and put a clear "every 0,05"... as I said.

    The server side gonna be something like this:

    socket.on("message", function (data) {

    var new_data = data.split(',');

            if (new_data[0] == 'alldata') {

                id = new_data[1];

                x = new_data[2];

                y = new_data[3];

                

                socket.broadcast.emit("message",

                  ?'alldata,' + id + ',' + x + ',' + y);

            }

  • >

    > >

    > > Every 0,05 seconds:>Send ("alldata," & "," & id & "," & x & "," & y)

    > >

    > For the server part or a client? I'm a little misunderstood.

    >

    > If I will send some kind of data to the server, how can I split it

    Your client. You gonna delete the pick, the "is moving?" condition and put a clear "every 0,05"... as I said.

    The server side gonna be something like this:

    socket.on("message", function (data) {

    var new_data = data.split(',');

            if (new_data[0] == 'alldata') {

                id = new_data[1];

                x = new_data[2];

                y = new_data[3];

                

                socket.broadcast.emit("message",

                  ?'alldata,' + id + ',' + x + ',' + y);

            }

    Alright. Thank you.

    Also, how "socket.broadcast.emit" is different from "socket.send"?

    breackzin

  • Vladoss

    broadcast Sends the message or event to every connected user in the current namespace, except to your self.

    It is useful to get off some "picks" from your client code.

    send, sends to everyone but does not support custom events.

    emit, does support.

    Also, my problem is here: scirra.com/forum/socketio-and-heroku_topic71952.html

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