• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED]Networking (buffer)

A

Andrea N

Guest
Hello,
i'm trying to make a multiplayer online game with server and client.
I wached some youtube tutorial and it's all ok, all works fine, the data that i send from the client to the server is correct.
I added some changes, i added some variables to sent from the client to the server using buffer, but when i received the informations from the server, the variables have wrong values.

I copy here my example code, the "Variable" are obviously all differents (this from the client):

//update coordinates
buffer_seek(global.buffer, buffer_seek_start, 0);
buffer_write(global.buffer, buffer_f64, 7);
buffer_write(global.buffer, buffer_string, playerUsername);
buffer_write(global.buffer, buffer_u32, Variable);
buffer_write(global.buffer, buffer_f32, Variable);
buffer_write(global.buffer, buffer_f32, Variable);
...
....
....
many lines later
network_send_packet(obj_controller.socket, global.buffer, scr_getBufferSize());

And this form the server:

case 7:
var playerUsername= buffer_read(buffer, buffer_string);
var Variable= buffer_read(buffer, buffer_u32);
var Variable= buffer_read(buffer, buffer_f32);
var Variable= buffer_read(buffer,buffer_f32);
var Variable= buffer_read(buffer, buffer_f32);
var Variable= buffer_read(buffer, buffer_f32);
....
....
.....
many lines later
if (file_exists(playerUsername + ".ini"))
{
// Update player data
ini_open(playerUsername + ".ini");
ini_write_real("a", "aa", Varible);
ini_write_real("a", "ab", Varible);
...
....
....
many lines later
}
ini_close();
break;


The server so receives the varibles from the client. I save them to a .ini file! But i have a problem, i have about 26 variables to send and for the last 9 i receive wrong information!
What's the problem?
Have i to use different buffers?
Am I sending too much information at the same time?
Can someone explain to me why i receive wrong informations?
For wrong informations i mean that i send (for example), playerlife=50, and i receive a casual number.

I hope I explained myself.
Thanks all for the answers.
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
What's the problem?
Most likely you are reading something not in the same order (or with a different data type) than how you have written it, and thus the reading position becomes off and mixes up the rest.

I also have question as to why you are writing your message ID (?) as a 64-bit floating-point value (in other words, as something designed to have precise fractions or big magnitudes)
 

The-any-Key

Member
If you use tcp you may send too much info so the protocol split the send and you receive a parts and it mess up the read. Try send in two different messages.

Also check so the buffer writing and reading correspond.

You may try write a f32 or a string value with u32 or u8 buffer write. Ex 1.1 to a u8 buffer will give a strange value on reading.

You maybe use the f16 that is not supported.

You may have a antivirus that mess up the travel from kernel to the game.

It may also be that the bug in f and u64 bit buffer is back again.
 

The-any-Key

Member
I believe this is only an issue when using the raw* networking functions
Sorry no. I tested it locally from GM to GM with the network send (not the raw* ones) function and it has the same "issue". TCP is a stream protocol (it can split whenever it want).
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
Sorry no. I tested it locally from GM to GM with the network send (not the raw* ones) function and it has the same "issue". TCP is a stream protocol (it can split whenever it want).
TCP is a stream protocol but GMS packet header includes a length field and it accumulates (or at least supposed to) until there's enough data to process an individual packet.
 
A

Andrea N

Guest
Most likely you are reading something not in the same order (or with a different data type) than how you have written it, and thus the reading position becomes off and mixes up the rest.

I also have question as to why you are writing your message ID (?) as a 64-bit floating-point value (in other words, as something designed to have precise fractions or big magnitudes)
Now i check the order but i think i ordered the varibles the right way. I understood that i need to use the same data type for the client and for the server! I used 64bitfloating value because i tried all the data type for all the variables (
I did not understand very well how much memory the variables need).

Now i put an image of my real code (to the left the server and to the right the client).
An image that show my variables when i'm playing, and my ini file.

The variables room, x and y are ok, the others have all casual values, i don't understand where i'm wrong.

Another quest, i use tile set and i see the square, (look the client_player image), how can i remove them?
Thanks for the attention.
 

Attachments

A

Andrea N

Guest
If you use tcp you may send too much info so the protocol split the send and you receive a parts and it mess up the read. Try send in two different messages.

Also check so the buffer writing and reading correspond.

You may try write a f32 or a string value with u32 or u8 buffer write. Ex 1.1 to a u8 buffer will give a strange value on reading.

You maybe use the f16 that is not supported.

You may have a antivirus that mess up the travel from kernel to the game.

It may also be that the bug in f and u64 bit buffer is back again.
Yes i'm using tcp, i followed this tutorial:
Do you think UDP works better? (obviously if I didn't make mistakes myself).
 

The-any-Key

Member
I did not understand very well how much memory the variables need
The server try to use the wrong buffers.

buffer_u8 can only hold a real number from 0 to 255.
var my_number=35; // OK
var my_next_number=290; // SUPER FAIL
var my_3_number=-34; // MEGA SUPER FAIL

So if you try <0 or 255< it wont store it correctly.
Ex if you collect 256 money you will get a strange number instead. Because 256 is bigger that 255 (max of a buffer_u8)
You need to keep track how big the number you send.

On the server use show_debug_message(sprite_index) and print out the rest of the values and you see what I mean.

Also note that sprite_index is a dynamic value and will change if you add, remove or rearrange the source tree in GM. So if you save the sprite_index and then you add a sprite in your project and then load the sprite_index it may point to a different sprite. Save the sprite name instead.
 
Last edited:
A

Andrea N

Guest
The server try to use the wrong buffers.

buffer_u8 can only hold a real number from 0 to 255.
var my_number=35; // OK
var my_next_number=290; // SUPER FAIL
var my_3_number=-34; // MEGA SUPER FAIL

So if you try <0 or 255< it wont store it correctly.
Ex if you collect 256 money you will get a strange number instead. Because 256 is bigger that 255 (max of a buffer_u8)
You need to keep track how big the number you send.

On the server use show_debug_message(sprite_index) and print out the rest of the values and you see what I mean.

Also note that sprite_index is a dynamic value and will change if you add, remove or rearrange the source tree in GM. So if you save the sprite_index and then you add a sprite in your project and then load the sprite_index it may point to a different sprite. Save the sprite name instead.
Sorry i don't understand how to use show_debug_message(). I tried to send the information one by one to understand what caused the first problem, and it's the varible player stamina (for now)! When i'm playing i draw the variable and the value of stamina is 100 so i think buffer_u32 is ok.
Now i try to send only variable "stamina" and watch what happens.
If you have any questions about the other variables iniside the .ini file, them were written first (during the login).
I'm stuck here!! Grrr
Thanks.
 

Attachments

The-any-Key

Member
Ex on the server you do this:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Check the value with:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Show_debug_message("sprite_index:" + string(sprite_index))
My guess is that you use the wrong buffer type for some of the values. All values that come to the client as wrong use wrong buffer type.
 
A

Andrea N

Guest
Ex on the server you do this:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Check the value with:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Show_debug_message("sprite_index:" + string(sprite_index))
My guess is that you use the wrong buffer type for some of the values. All values that come to the client as wrong use wrong buffer type.
Now i tried with the varibale "experience" and the value is the same of the varible "stamina" i used show_debug_message.
 

Attachments

A

Andrea N

Guest
Ex on the server you do this:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Check the value with:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Show_debug_message("sprite_index:" + string(sprite_index))
My guess is that you use the wrong buffer type for some of the values. All values that come to the client as wrong use wrong buffer type.
Oh sorry i used show debug message on client!!
 
A

Andrea N

Guest
Ex on the server you do this:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Check the value with:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Show_debug_message("sprite_index:" + string(sprite_index))
My guess is that you use the wrong buffer type for some of the values. All values that come to the client as wrong use wrong buffer type.
Done
Ex on the server you do this:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Check the value with:
Code:
buffer_write(global.buffer, buffer_u8, sprite_index);
Show_debug_message("sprite_index:" + string(sprite_index))
My guess is that you use the wrong buffer type for some of the values. All values that come to the client as wrong use wrong buffer type.
Done! And the value is as the ini file!
 

Attachments

Top