Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transmitting different data types through a socket

Status
Not open for further replies.

Hippocrat

Technical User
Sep 28, 2003
2
CA
Ive looked through the posts and couldnt find quite what I needed to know.

Im new to socket programming and have a fairly
straight-forward question (I believe)

anyway I have established a connection between my server and client apps using a tcp socket (not UDP) I am able to send string data through the buffer but for the life of me I cant figure out how to send other data (i.e integers)

Ive tried using ntohl() and htonl() but they are either the wrong functions or I am using them incorrectly

Im using Visual C++ its an MFC dialog app but Im not using any wrapper class just the Winsock API

anyone know how to send numerical data through a socket?
or know of a clear precise example somewhere.

I appoligize in advance if this post is off topic.
and welcome any advise
thnx
 
If you are looking at sending human readable numbers down the wire, then you could do a sprintf(buffer, '%d', ...) and then shove the contents of buffer down the wire.

You need to think about how to tell the other end that you are about to send an integer down the wire and then send the raw data - the server should then realise what to do with the data on the other end.

Scotty
 
thanks for the quick reply .. human readable data is no problem I basically use the method you suggested

The problem lies in the later .. say for some reason I want to tell the server to repeat some_function() (x) times .. I need the client to provide (x) that is where It gets sticky I've not found a way to tell the recieving socket that the data is to be interpreted as an integer value and not string data.

doesnt seem to be a lot of info on the subject oddly enough as this has to be an extremely common situation

the search continues
thanks again for your reply



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top