sending messages - recommendations
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
the_moo
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:
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;send(...,(char*)&thePing,...);
Btw: this is actually mentioned in the Forum FAQ.
enum Bool { True, False, FileNotFound };
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,
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,
the_moo
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement