Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualpapalazaru

Posted 20 December 2012 - 11:10 AM

You need to look into 'serialisation'.

What serialisation does is convert your object properties back and forth into byte streams / bitstreams, or a byte array.

It is similar to writing or reading your data into a binary file, or even a screen console output, if you are more familiar with that.

If you use UDP, then you can wrap a char array with a binary stream handler to convert your objects to and from binary.

Look up boost serialization, if you want to delve deeper.

But really, if you want the short answer, you would do something like this


//--------------------------------
// player definition.
//--------------------------------
struct Player
{ 
	float px;
	float py;
	float vx;
	float vy;
	u32 actions;
};


//--------------------------------
// CLIENT
//--------------------------------
Player player;
sendto(socket_handle, &player, sizeof(player), 0, &server_address, sizeof(server_address));

//--------------------------------
// SERVER
//--------------------------------
Player player;
recvfrom(socket_handle, &player, sizeof(player), 0, &client_address, &client_address_len);

Note that I strongly suggest you do not use that method and do proper serialization, or at the very least understand the many problems associated with the code above.

#4papalazaru

Posted 20 December 2012 - 11:10 AM

You need to look into 'serialisation'.

What serialisation does is convert your object properties back and forth into byte streams / bitstreams, or a byte array.

It is similar to writing or reading your data into a binary file, or even a screen console output, if you are more familiar with that.

If you use UDP, then you can wrap a char array with a binary stream handler to convert your objects to and from binary.

Look up boost serialization, if you want to delve deeper.

But really, if you want the short answer, you would do something like this


//--------------------------------
// player definition.
//--------------------------------
struct Player
{ 
	float px;
	float py;
	float vx;
	float vy;
	u32 actions;
};


//--------------------------------
// CLIENT
//--------------------------------
Player player;
sendto(socket_handle, &player, sizeof(player), 0, &server_address, sizeof(server_address));

//--------------------------------
// SERVER
//--------------------------------
Player player;
recvfrom(socket_handle, &player, sizeof(player), 0, &client_address, &client_address_len);

Note that I strongly suggest you do not use that method and do proper serialization, or at the very least understand the many problems associated with the code above.

#3papalazaru

Posted 20 December 2012 - 11:09 AM

You need to look into 'serialisation'.

What serialisation does is convert your object properties back and forth into byte streams / bitstreams, or a byte array.

It is similar to writing or reading your data into a binary file, or even a screen console output, if you are more familiar with that.

If you use UDP, then you can wrap a char array with a binary stream handler to convert your objects to and from binary.

Look up boost serialization, if you want to delve deeper.

But really, if you want the short answer, you would do something like this


//--------------------------------
// player definition.
//--------------------------------
struct Player
{ 
	float px;
	float py;
	float vx;
	float vy;
	u32 actions;
};


//--------------------------------
// CLIENT
//--------------------------------
Player player;
sendto(socket_handle, &player, sizeof(player), 0, &server_address, sizeof(server_address));

//--------------------------------
// SERVER
//--------------------------------
Player player;
recvfrom(socket_handle, &player, sizeof(player), 0, &client_address, &client_address_len);

Note that I strongly suggest you do not use that method and do proper serialization, or at the very least understand the many problems associated with that.

#2papalazaru

Posted 20 December 2012 - 11:09 AM

You need to look into 'serialisation'.

What serialisation does is convert your object properties back and forth into byte streams / bitstreams, or a byte array.

It is similar to writing or reading your data into a binary file, or even a screen console output, if you are more familiar with that.

If you use UDP, then you can wrap a char array with a binary stream handler to convert your objects to and from binary.

Look up boost serialization, if you want to delve deeper.

But really, if you want the short answer, you would do something like this

//--------------------------------
// player definition.
//--------------------------------
struct Player
{ 
	float px;
	float py;
	float vx;
	float vy;
	u32 actions;
};

//--------------------------------
// CLIENT
//--------------------------------
Player player;
sendto(socket_handle, &player, sizeof(player), 0, &server_address, sizeof(server_address));
//--------------------------------
// SERVER
//--------------------------------
Player player;
recvfrom(socket_handle, &player, sizeof(player), 0, &client_address, &client_address_len);

Note that I strongly suggest you do not use that method and do proper serialization, or at the very least understand the many problems associated with that.

#1papalazaru

Posted 20 December 2012 - 11:08 AM

You need to look into 'serialisation'.

What serialisation does is convert your object properties back and forth into byte streams / bitstreams, or a byte array.

It is similar to writing or reading your data into a binary file, or even a screen console output, if you are more familiar with that.

If you use UDP, then you can wrap a char array with a binary stream handler to convert your objects to and from binary.

Look up boost serialization, if you want to delve deeper.

But really, if you want the short answer, you would do something like this

//--------------------------------
// CLIENT
//--------------------------------
Player player;
sendto(socket_handle, &player, sizeof(player), 0, &server_address, sizeof(server_address));
//--------------------------------
// SERVER
//--------------------------------
Player player;
recvfrom(socket_handle, &player, sizeof(player), 0, &client_address, &client_address_len);

Note that I strongly suggest you do not use that method and do proper serialization, or at the very least understand the many problems associated with that.

PARTNERS