Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sockets



On Sat, 16 Oct 2004 19:59:10 -0500 (EST)
Anthony Gabrielson <agabriel at home.tzo.org> wrote:

> 
> Hello,
> 	I'm looking for a sockets example that isn't an echo server...  
> I'm looking for an example that sends an interger, or a Struct,
> something non char.  Does anyone have a link or advice?  
Pretty much what David replied. Once you open up a channel, it is pretty
much like any other I/O in Linux. I generally do not like to send binary
data for interoperability issues. Having been heavily involved in data
transfers between big and little endian machines, ASCII and EBCDIC, I
generally prefer to convert upwards. Also remember that the compiler may
generate fillers in a structure:
struct {
	char a;
	double b;
};
The length of the struct is 16 bytes because b is be aligned on a 64 bit
boundary (on 386 Linux). And for this reason, you should serialize. 

There is a protocol called ASN.1 (http://asn1.elibel.tm.fr/en/) that is
used in some places. Essentially, everything is encoded into a TLD
(type-length-data) scheme where every data type is encoded as a byte
(eg. 32 bit int might be 1, char string (eg. octet) might be 2, user
defined 4, ...). The length is usually encoded in 7 bits. If the length
is longer than 127, then the length byte becomes a negative length of
the length. Example, sending a packet containing a string "abc", and int
123:
40X0A23abc13123
The 0x0A is the length of the packet 

-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.blu.org/pipermail/discuss/attachments/20041017/5452de43/attachment.sig>



BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org