Sending "custom" messages through winsock

Hey, I've recently been learning how to implement a winsock prorgam (very difficult may I add, I still havn't sused how to get it working over the internet, if anyone wants to help with that PLEASE contact me sblasbla@hotmail.com) and I've got as far as implementing a chat program over a LAN connection, simple but effective, but I was wondering if there is a way to send a "Custom" message through WinSock i.e.

1
2
3
4
5
6
struct PlayerScoreMsg 
{
	unsigned long frags; // Player's frag count.
	unsigned long deaths; // Player's death tally.
};


Say I wanted to send that struct through, is it possible and how?
is it possible...
Of course:P...

You could just cast the whole thing to (char) and send it with the length of sizeof(PlayerSCoreMsg);
But this is not to recommend.

Personally I do prefer to extract the data of the structures and build a string from it, which I will send later:

e.g. something like the following
1
2
3
stringstream ss;
ss << PlayerScoreMsg.frags << '-' << PlayerScoreMsg.deaths << '-';
send(socket, ss.str().data(), ss.str().length, ...)


EDIT: I suggest reading the following article: chapter 3.2 and 3.3 http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html <- this is all you need, i guess (and much more on winsock :) )
Last edited on
Thank you, that is really helpfull :)
Btw when you did the
send(socket, ss().data(), ss.str().length, ...)

Was the "..." to symbolize etc. or is that a legitimate parameter for a Function?
Last edited on
hmmm?... I think I used it as etc... but it is also a valid parameter for the char* buffer of the send instruction...
Topic archived. No new replies allowed.