You can either memcpy your struct to an array of chars and send that or cast your struct as an array of chars. It''s the same thing.
You should, however, never RECV to a struct or if you really want to, RECV to a temporary struct (it makes checking the header a little easier) and copy it to an array of chars. Otherwise you''re shooting yourself in the foot when you go to see if you have the whole message or two or more messages in one packet. You need to recieve to an array of chars and then do some checking before you memcpy the char buffer into the struct.
With my Winsock class I have a message class that handles all of this so when I call GetMessage() it will only return a message struct if there''s a complete message available. Then I just keep calling GetMessage() until it doesn''t return a message.
The method sets the message.type to -1 of there''s not a message available. There are a couple other negative numbers it''ll return for checking why it didn''t return a message. Those were just for debugging though.
Ben
IcarusIndie.com [
The Rabbit Hole |
The Labyrinth |
DevZone |
Gang Wars |
The Wall |
Hosting |
Tiberian Merchandise!!!! |
GameShot ]