Windows trying to read received tcp packet: illegal argument type

Z

Zodiaq

Guest
i'm trying to read a received tcp packet from custom c# server. i copy the code from an officiel example (NetworkDemo) i'm stuck on this for days now. all that's happening is the server sending a packet containing a message and i'm trying to read it and flash it to the debug console. here is the code script that i called on a Async event of an object after sending a packet to the server:

Code:
/// Read incoming data to the server from a connected saocket
{ 
    // get the buffer the data resides in
  var buff2 = ds_map_find_value(async_load, "buffer");
    
    // read ythe command
    var cmd = buffer_read(buff2, buffer_u8 );

    // Get the socket ID - this is the CLIENT socket ID. We can use this as a "key" for this client
    var socks = ds_map_find_value(async_load, "id");
  show_debug_message("received : "+cmd+" id : "+socks);


 
}


upload_2018-2-22_17-0-37.png
 

jo-thijs

Member
i'm trying to read a received tcp packet from custom c# server. i copy the code from an officiel example (NetworkDemo) i'm stuck on this for days now. all that's happening is the server sending a packet containing a message and i'm trying to read it and flash it to the debug console. here is the code script that i called on a Async event of an object after sending a packet to the server:

Code:
/// Read incoming data to the server from a connected saocket
{
    // get the buffer the data resides in
  var buff2 = ds_map_find_value(async_load, "buffer");
   
    // read ythe command
    var cmd = buffer_read(buff2, buffer_u8 );

    // Get the socket ID - this is the CLIENT socket ID. We can use this as a "key" for this client
    var socks = ds_map_find_value(async_load, "id");
  show_debug_message("received : "+cmd+" id : "+socks);


 
}


View attachment 16630
Hi and welcome to the GMC!

The debugger tells you that buff2 is the value undefined, meaning that the map async_load did not contain the key "buffer".

Are you sure ds_map_find_value(async_load, "type") is network_type_data?

If you iterate over the contents of async_load, what keys do you get?
 
Z

Zodiaq

Guest
Hi and welcome to the GMC!

The debugger tells you that buff2 is the value undefined, meaning that the map async_load did not contain the key "buffer".

Are you sure ds_map_find_value(async_load, "type") is network_type_data?

If you iterate over the contents of async_load, what keys do you get?
Hello jo, thank you for responding!
i'm very sorry i don't know how to answer to neither of your questions. however, after reading your response and checking docs this :
The asynchronous event will contain a special temporary ds_map (it is removed at the end of the event automatically) which contains different information depending on the type of incoming data from the network. In this case, we are assuming that the map has been checked and found to be a buffer data packet sent from a client.
i think that game maker defines the packet by the "type" when it's sent and that's valide between server and client both made with GMS, but in my case i'm using non GMS server (c#) so i'm using "network_send_raw" to get rid of GMS header and the packet received doesn't contain a GMS header too which i THINK that GMS knows the type from that header. for second question i'm sorry i don't understand..
 
Last edited by a moderator:

jo-thijs

Member
Hello jo, thank you for responding!
i'm very sorry i don't know how to answer to neither of your questions. however, after reading your response and checking docs this :
i think that game maker defines the packet by the "type" when it's sent and that's valide between server and client both made with GMS, but in my case i'm using non GMS server (c#) so i'm using "network_send_raw" to get rid of GMS header and the packet received doesn't contain a GMS header too which i THINK that GMS knows the type from that header. for second question i'm sorry i don't understand..
No, the type should be independent of whether you used raw data or not.
It is true that GameMaker adds a header to messages, but what's of importance to figure out the type is the TCP header, which is the same for both.

My second question was to basically run this code in your script and test what it outputs:
Code:
var s = "{ ";

if !ds_map_empty(async_load) {
    for(key = ds_map_find_first(async_load);
            !is_undefined(key);
            key = ds_map_find_next(async_load, key)) {
        s += string(key) + " ,  ";
    }
}

show_debug_message(s + " }");
 
Z

Zodiaq

Guest
No, the type should be independent of whether you used raw data or not.
It is true that GameMaker adds a header to messages, but what's of importance to figure out the type is the TCP header, which is the same for both.

My second question was to basically run this code in your script and test what it outputs:
Code:
var s = "{ ";

if !ds_map_empty(async_load) {
    for(key = ds_map_find_first(async_load);
            !is_undefined(key);
            key = ds_map_find_next(async_load, key)) {
        s += string(key) + " ,  ";
    }
}

show_debug_message(s + " }");
Ah, okey thanks for the clarification. i implement that piece of code and it returns this:
Code:
{ succeeded ,  ip ,  port ,  socket ,  type ,  id ,   }
{ ip ,  port ,  buffer ,  size ,  type ,  id ,   }
 

jo-thijs

Member
Ah, okey thanks for the clarification. i implement that piece of code and it returns this:
Code:
{ succeeded ,  ip ,  port ,  socket ,  type ,  id ,   }
{ ip ,  port ,  buffer ,  size ,  type ,  id ,   }
I take it the first one causes trouble?
The first async_load had as type network_type_connect, so there is no buffer there as no data has been sent yet, only a connection has been established.
If you run your script then, then it is normal that you get that error message.
You should only run your script if async_load[?"type"] == network_type_data.
 
Z

Zodiaq

Guest
I take it the first one causes trouble?
The first async_load had as type network_type_connect, so there is no buffer there as no data has been sent yet, only a connection has been established.
If you run your script then, then it is normal that you get that error message.
You should only run your script if async_load[?"type"] == network_type_data.
you right sorry, it's the second one where the problem lays. i've added
Code:
async_load[?"type"] == network_type_data
and got
Code:
{ ip ,  port ,  buffer ,  size ,  type ,  id ,   }
 

jo-thijs

Member
you right sorry, it's the second one where the problem lays. i've added
Code:
async_load[?"type"] == network_type_data
and got
Code:
{ ip ,  port ,  buffer ,  size ,  type ,  id ,   }
And what does this output?
Code:
show_message(string(async_load[?"buffer"]))
 
Z

Zodiaq

Guest
And what does this output?
Code:
show_message(string(async_load[?"buffer"]))
weird, it returns increasing number every time i restart the game (gamerestart() button) first run shows "1" second "2" and so on.. and last shows 7, same amue as buffer and socket. that code supposed to return the value?upload_2018-2-22_22-5-30.png
 

jo-thijs

Member
weird, it returns increasing number every time i restart the game (gamerestart() button) first run shows "1" second "2" and so on.. and last shows 7, same amue as buffer and socket. that code supposed to return the value?View attachment 16636
Yes, as long as you're not getting an error, it's supposed to return that.
However, in your original post you posted a screenshot that said the value was <undefined>, which is what it's supposed to be when you get an error.
So, you're not reproducing the error anymore?
 
Z

Zodiaq

Guest
Yes, as long as you're not getting an error, it's supposed to return that.
However, in your original post you posted a screenshot that said the value was <undefined>, which is what it's supposed to be when you get an error.
So, you're not reproducing the error anymore?
no, i think that async_load(buffer) returns the value from the first async operation which is send_packet. there was no reader buffer there, however when i add a reader buffer it says it's "undefined" and the execution doesn't reach the show_message
upload_2018-2-22_22-32-26.png
 

jo-thijs

Member
no, i think that async_load(buffer) returns the value from the first async operation which is send_packet. there was no reader buffer there, however when i add a reader buffer it says it's "undefined" and the execution doesn't reach the show_message
View attachment 16637
Well, you're supposed to put the read_message inbetween lines 32 and 33 so that execution does reach that point.

Try this, change your rcv script to:
Code:
/// Read incoming data to the server from a connected saocket
{
    // get the buffer the data resides in
  var buff2 = ds_map_find_value(async_load, "buffer");
    
    if is_undefined(buff2) {
        var s = "{ ";
        
        if !ds_map_empty(async_load) {
            for(key = ds_map_find_first(async_load);
                    !is_undefined(key);
                        key = ds_map_find_next(async_load, key)) {
                s += string(key) + " ,  ";
            }
        }
        
        show_debug_message(s + " }");
    }
    
    // read ythe command
    var cmd = buffer_read(buff2, buffer_u8 );

    // Get the socket ID - this is the CLIENT socket ID. We can use this as a "key" for this client
    var socks = ds_map_find_value(async_load, "id");
  show_debug_message("received : "+cmd+" id : "+socks);

}
Reproduce the error and tell us what the show_debug_message outputed.
 
Z

Zodiaq

Guest
Well, you're supposed to put the read_message inbetween lines 32 and 33 so that execution does reach that point.

Try this, change your rcv script to:
Code:
/// Read incoming data to the server from a connected saocket
{
    // get the buffer the data resides in
  var buff2 = ds_map_find_value(async_load, "buffer");
   
    if is_undefined(buff2) {
        var s = "{ ";
       
        if !ds_map_empty(async_load) {
            for(key = ds_map_find_first(async_load);
                    !is_undefined(key);
                        key = ds_map_find_next(async_load, key)) {
                s += string(key) + " ,  ";
            }
        }
       
        show_debug_message(s + " }");
    }
   
    // read ythe command
    var cmd = buffer_read(buff2, buffer_u8 );

    // Get the socket ID - this is the CLIENT socket ID. We can use this as a "key" for this client
    var socks = ds_map_find_value(async_load, "id");
  show_debug_message("received : "+cmd+" id : "+socks);

}
Reproduce the error and tell us what the show_debug_message outputed.
same, breaks at line 19
upload_2018-2-22_22-50-40.png
 
Z

Zodiaq

Guest
oh, thanks a lot for everything. i added some optimization and i manage to read the incoming packet successfully. thank you for helping me all along :)
upload_2018-2-22_23-28-14.png
 
Last edited by a moderator:
Z

Zodiaq

Guest
so after all it turns out that checking if async_load[?"type"] == network_type_data is the key. so my first code must be trying to process a non data type load?
 
Top