Archived

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

way_out_west

Just chars?

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