Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

way_out_west

Just chars?

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

I''m slowly beginning to understand what and how sockets work. There is just one question that I really need to ask. Winsock... if I''m using the TCP/IP protocol suite, does that mean that I can only evcer send and recieve characters. I mean, what about floats? And what if I wanted to send a bool? Am I restricted to using chars and their ASCII codes to determine if they are integer values?

Share this post


Link to post
Share on other sites
Advertisement
No, you can send and receive anything you''d like. Reading and writing to a socket is a bit like reading and writing from a file. The socket is analogous to a file handle.

The send() and recv() functions take a char pointer, but you can cast the data you wish to send. For example:


int someInteger = 5;
send(mySocket, (char *)&someInteger, sizeof(someInteger), 0);

Share this post


Link to post
Share on other sites
Right. Think of the data as an array of bytes rather than an array of characters (a char is effectively a byte; sizeof(char) == sizeof(byte)). Since every possible data type is composed of bytes/chars, you have the ability to send any data type over a socket by casting, as MattB showed.

RapscallionGL - arriving soon.

Share this post


Link to post
Share on other sites

  • 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!