Legacy GM Send char* over network_send_udp()

J

Juzek

Guest
When sending information over my LAN to my server (c++) by building up a buffer, and using network_send_udp(), I cannot interpret what comes across. The server is set up to read in a c++ char* type data, and I would like to be able to send a string (or numbers) that can be interpreted correctly.

When I use the simplest thing I can, ( type buffer_u8) it still gets interpreted as garble, and often receives multiple packets for one variable.

What else does Game Maker Studio send attach to the buffer? is it some sort of indication that this is a game maker variable of type string?

here is my code to send the number 12:
var t_buffer = buffer_create(256, buffer_grow, 1);
buffer_seek(t_buffer,buffer_seek_start, 0);
buffer_write (t_buffer, buffer_u8, 12);
network_send_udp(server_udp,"127.0.0.1",63258,t_buffer,buffer_tell(t_buffer));

Here is what I would like to do, assuming convert_to_c_string was a function:
var t_buffer = buffer_create(256, buffer_grow, 1); buffer_seek(t_buffer,buffer_seek_start, 0);
buffer_write (t_buffer, buffer_string,"command 321 234 1 0");
t_buffer = convert_to_c_string (t_buffer);
network_send_udp(server_udp,"127.0.0.1",63258,t_buffer,buffer_tell(t_buffer));
 

hippyman

Member
GM:S only uses two types.

double
char*

There is a function that converts a variable to a gamemaker string (char*).
Code:
var number = 50; // double data type
var word = string(number); // char* data type

//send word to send char* instead of double
This is my understanding on how C++ sees GM variables.

I'm not sure if this is what you're asking, but if you're trying to make sure a variable is a string before sending it then this is the way.
 

Yal

šŸ§ *penguin noises*
GMC Elder
Wait, char* means char pointer... I don't think it makes sense to send over a pointer to another computer, since it's the memory location where a string is stored. You'd send over all the chars one by one instead and then reassemble them in the target computer.
 
J

Juzek

Guest
Ok, let me re-phrase my question.

I can send the GML string over to my server. my server is just a repeater at the moment, and it sends it right back. Game Maker understands the reply as a GML string. everything works great on the game maker side.

My question is: What do I need to do to get my c++ server to understand a GML string? At the moment my server is set up to receive information as an array of char ( sorry Yal, I said char* to differentiate from a std::string ) I am using the Winsock recvfrom() function which looks like this:
Code:
recvfrom(SOCKET,char*,int,int,struct sockaddr*,int*);

//recvfrom( my_socket, pointer_to_my_buffer_char_array, length_of_writing_buffer, IP_information, options,pointer_to_IP_address_info,  length_of_socket_read_buffer)
Thanks for the replies, any thoughts?
 
B

Braffolk

Guest
Since you are using another language for the server, make sure you are using network_send_udp_raw or network_send_raw
 
Top