Jump to content
  • Advertisement
Sign in to follow this  
Unconquerable

Sending numbers?

This topic is 4342 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

How does one send numbers with Winsock? I've only been sending lettters with: int send( SOCKET s, const char* buf, int len, int flags ); Thanks.

Share this post


Link to post
Share on other sites
Advertisement
It would look like this:
int i = 43;
send( socket, reinterpret_cast< char * >( &i ), sizeof( i ), 0 );

You would, however, probably get a better answer with a description of what it is you are trying to do, exactly.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Unconquerable
How does one send numbers with Winsock? I've only been sending lettters with:

int send(
SOCKET s,
const char* buf,
int len,
int flags
);


Thanks.





You can also send a struct structure containing just about anything (note- pointer data in an element would be invalid....).

'buf' would be a pointer to the struct var (cast to char*)
'len' would be sizeof(structtypeX)







Share this post


Link to post
Share on other sites
Quote:
Original post by Unconquerable
How does one send numbers with Winsock? I've only been sending lettters with:

int send(
SOCKET s,
const char* buf,
int len,
int flags
);


Actually, char is just an 8-bit number, so you've been sending numbers all along :-)

Share this post


Link to post
Share on other sites
Also, its ussually a good idea to convert to network order by using

htonl(int x) //host to network order, when sending

and

ntohl(int x) //network to host, when receiving


This only matters if you are sending data between different systems, but it saves a lot of headache later on even if you don't.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!