Jump to content

Raknet send and receive struct


ParaToxic
 Share

Recommended Posts

Hello community,

first big thank to Engineer Ken for the good Raknet tutorial.

 

I would like to send an receive a little struct with the position and the rotation of an entity.

 

I made it like this to send :

struct Player
{
float a,b;
};
//.......

Player pl;
pl.a = 12.0f;
pl.b = 4.5f;
//......
server->server->Send(reinterpret_cast<char*>(&pl),sizeof(pl), HIGH_PRIORITY, RELIABLE_ORDERED, 0, RakNet::UNASSIGNED_SYSTEM_ADDRESS, true);

 

For the client i don't know how to convert the client->p->data to a created "Player" struct like pl2.

 

Maybe somebody can tell me how to do that.

Thanks ;D

Link to comment
Share on other sites

Are you doing this in 2D? You only have a and b. I would expect 2 x, y, z for position and rotation. Given you really need x, y, z use BitStreams. In fact use BitStreams no matter what. It's what's recommended. It also has WriteVector() and ReadVector() function build into it to write x, y, z and read x, y, z values.

 

http://www.jenkinssoftware.com/raknet/manual/bitstreams.html

Link to comment
Share on other sites

I sent my structure successfully when I copy the client to an other PC in at my home it can't connect.

In the Client properties I have my IP which is listed by the server under IP adresses at place 1.

 

Maybe somebody can tell me why?

 

I think the problem is the Socket IP,which is 127.0.0.1 ,so localhost.How can I solve that?

 

Thanks and good night ;D

Link to comment
Share on other sites

  • 2 weeks later...

I sent my structure successfully when I copy the client to an other PC in at my home it can't connect.

In the Client properties I have my IP which is listed by the server under IP adresses at place 1.

 

Maybe somebody can tell me why?

 

I think the problem is the Socket IP,which is 127.0.0.1 ,so localhost.How can I solve that?

 

Thanks and good night ;D

 

Hi Para Toxic,

 

I would highly reccomend sending BitStreams instead of Structs. I don't think I ever send structs at all.

 

If the IP u are using to connect is 127.0.0.1 then you are networking with yourself. If you are trying to network between 2 computers you need to determine the semi-dynamic IP of the server computer (something like 192.168.x.x)and connect to that instead. If you want over the internet you need the fully dynamic IP. Some day I will write a tutorial on how to to do LAN server discovery so you don't have to hard code the IP addresses but that is for another day. In the meantime you can look at the example LAN server discovery code that comes with RakNet.

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Ok I made my first little Multiplayer Game :)

Thank you for support and the great Tutorials ;D

 

gratz

 

Ok I made my first little Multiplayer Game ;)

Thank you for support and the great Tutorials ;D

 

gratz

STS - Scarlet Thread Studios

AKA: Engineer Ken

 

Fact: Game Development is hard... very bloody hard.. If you are not prepared to accept that.. Please give up now!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...