Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How do I send [this] over a socket?

Answer Posted / chaitanya

Anything other than single bytes of data will probably get mangled unless you take care. For integer values you can use htons() and friends, and strings are really just a bunch of single bytes, so those should be OK. Be careful not to send a pointer to a string though, since the pointer will be meaningless on another machine. If you need to send a struct, you should write sendthisstruct() and readthisstruct() functions for it that do all the work of taking the structure apart on one side, and putting it back together on the other. If you need to send floats, you may have a lot of work ahead of you. You should read RFC 1014 which is about portable ways of getting data from one machine to another (thanks to Andrew Gabriel for pointing this out).

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What's the difference between a socket and a port?

898


Where is the socket located?

947


How do unix sockets work?

899


What is the difference between read() and recv()?

2017


How many socket connections can a server handle?

907


Can multiple clients connect to same socket?

950


What exactly is a socket?

994


What is active unix domain sockets?

953


Is a socket a file?

909


What are the pros/cons of select(), non-blocking I/O and SIGIO?

1408


What is a socket address?

963


What's better 6pt or 12pt sockets?

869


How can I force a socket to send the data in its buffer?

1670


Why do we need sockets?

890


What is the difference between SO_REUSEADDR and SO_REUSEPORT?

1844