Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   how to transfer object using socket (tcp/ip) (http://www.programmingforums.org/showthread.php?t=13856)

amitpansuria Aug 27th, 2007 1:17 AM

how to transfer object using socket (tcp/ip)
 
helo,
if i wan to develping socket application using c++on linux.
if i want to transfer whole object then how can i transfer object from server to client using socket(tcp/ip) protocol
Regards,
Amit

lectricpharaoh Aug 27th, 2007 2:07 AM

If it's between machines with the same endianness, you can just trasmit it as a block of bytes. If not, or if you simply want a more portable solution, you can serialize the structure, and then send the bytestream out. Take your pic; it depends on your needs.

Eoin Aug 27th, 2007 9:54 AM

Boost.Serialization is very comprehensive library which could be helpful.

amitpansuria Aug 28th, 2007 2:40 AM

what is serialization and how i use it
 
Quote:

Originally Posted by lectricpharaoh (Post 132874)
If it's between machines with the same endianness, you can just trasmit it as a block of bytes. If not, or if you simply want a more portable solution, you can serialize the structure, and then send the bytestream out. Take your pic; it depends on your needs.

helo u say that i want to serialize the structure or object.
can u tell me what exactly is serialization and how i implement serialization
Amit

lectricpharaoh Aug 28th, 2007 5:44 AM

Quote:

Originally Posted by amitpansuria
helo u say that i want to serialize the structure or object.
can u tell me what exactly is serialization and how i implement serialization
Amit

Serialization, in this sense, is the process of taking a chunk of data and coverting it to a sequence of bytes for some kind of operation (generally writing to disk or sending across a network connection). In some contexts, the disk write/network transmission is subsumed in the term 'serialization'.

One of the benefits of serialization is it converts internal representations of data to a series of bytes, and thus the byte order of the CPU doesn't matter. Say you transmit a 32-bit int across a network connection, and the sending computer is, say, an Intel x86-based machine. The x86 architecture is 'little endian', meaning that multi-byte values are ordered in memory with the least significant byte first. In other words, the value 0xAABBCCDD would be four bytes, in this order: 0xDD, 0xCC, 0xBB, and 0xAA. The receiving computer, on the other hand, might be a big-endian machine, expecting the bytes like so: 0xAA, 0xBB, 0xCC, and 0xDD. Hell, maybe the receiving machine uses 64-bit ints. Either way, you have a problem.

Another benefit is that many functions for writing to disk or communicating across a network expect a buffer of bytes to work with. Serialization gives you this buffer of bytes.


All times are GMT -5. The time now is 1:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC