[Socket.io] Players coordinates

Get help using Construct 2

Post » Wed Jul 17, 2013 6:54 pm

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?
B
39
S
16
G
6
Posts: 238
Reputation: 7,915

Post » Wed Jul 17, 2013 7:26 pm

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.
B
7
S
3
G
1
Posts: 154
Reputation: 1,812

Post » Wed Jul 17, 2013 7:27 pm

@Vladoss
B
7
S
3
G
1
Posts: 154
Reputation: 1,812

Post » Wed Jul 17, 2013 8:10 pm

[QUOTE=breackzin]
Instead, use every 0,05 seconds.
[/QUOTE]

Are you sure this will help?
What about 0,1?
B
39
S
16
G
6
Posts: 238
Reputation: 7,915

Post » Thu Jul 18, 2013 12:29 am

Get it tested and see for yourself.
B
7
S
3
G
1
Posts: 154
Reputation: 1,812

Post » Thu Jul 18, 2013 4:03 pm

[QUOTE=breackzin] Get it tested and see for yourself. [/QUOTE]

It still did not helped. Maybe there is a problem with my code?
B
39
S
16
G
6
Posts: 238
Reputation: 7,915

Post » Fri Jul 19, 2013 12:02 am

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?

@Vladossbreackzin2013-07-19 01:29:35
B
7
S
3
G
1
Posts: 154
Reputation: 1,812

Post » Fri Jul 19, 2013 9:30 am

[QUOTE=breackzin]
Every 0,05 seconds:>Send ("alldata," & "," & id & "," & x & "," & y)
[/QUOTE]
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?

[QUOTE=breackzin]
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?
[/QUOTE]

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
B
39
S
16
G
6
Posts: 238
Reputation: 7,915

Post » Fri Jul 19, 2013 2:07 pm

[QUOTE=Vladoss] [QUOTE=breackzin]
Every 0,05 seconds:>Send ("alldata," & "," & id & "," & x & "," & y)
[/QUOTE]
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[/QUOTE]

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);
        }
breackzin2013-07-19 14:07:44
B
7
S
3
G
1
Posts: 154
Reputation: 1,812

Post » Fri Jul 19, 2013 2:16 pm

[QUOTE=breackzin] [QUOTE=Vladoss] [QUOTE=breackzin]
Every 0,05 seconds:>Send ("alldata," & "," & id & "," & x & "," & y)
[/QUOTE]
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[/QUOTE]

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);
        }
[/QUOTE]

Alright. Thank you.

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

@breackzinVladoss2013-07-19 14:41:30
B
39
S
16
G
6
Posts: 238
Reputation: 7,915

Next

Return to How do I....?

Who is online

Users browsing this forum: NN81 and 13 guests