Advertisement Jump to content
Sign in to follow this  

sending messages - recommendations

This topic is 4876 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey again (second time in one day!), i've been messing around with this pinging and have sort of run into a brick wall: when sending information back from a ping (so a computer has done a broadcast and a server has picked it up), what method should i use? by this i mean not what function (i know send()), but how should i go about organising the data for sending since you can only send text (well, char*)? i've thought (and tried to implement) something like this: - first send a header to tell the receiver what the data is about (eg. "-p" for ping) - then, send the actual information for the receiver to read (eg. somestring) using this i then firstly read the first 2 chars (the header), then i read until a space (so " ") and put the information into the relevant variable. my problem was that this will get a little tedious when sending a few different types of data or information at once (like what i want to do when i ping). when i ping, i want to have the listening computer send back their player name and ip address (port number is constant in my game). so this would mean i need to send a header for player name, then the player's name, then a header for ip address and finally the ip address - this all seems a bit much! so back to my question/topic: what method for transferring data would you recommend? (also there is the fact that not all data is char*... what to do then?) im sorry for asking so many questions, but its hard to find the answer anywhere that ive looked! thanks for any ideas

Share this post

Link to post
Share on other sites
send() and recv() have a stupid type for the buffer. They both take a char*, but you can send any data. I don't know why they don't take a void*, like any sane function would.

For example:

struct Ping
int nTime;
unsigned int dwIP;
unsigned short nPort;

Ping thePing;
thePing.nTime = time();
thePing.dwIP = this_ip;
thePing.nPort = this_port;

Share this post

Link to post
Share on other sites
thanks for that evil steve!
sorry about the faq thing. i didn't know exactly what i would be looking for (hence my ask for recommendations) [smile]. ill be sure to read through it more thoroughly next time i need some help before posting.

ive got the game compiling now so ill see how it goes and if i have any more problems concerning sending data ill post (if i cant find the answer elsewhere of course [wink]).

thanks again,

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!