Thread: New to the forum and have already a question >.<

  1. #1
    Registered User
    Join Date
    Nov 2004

    New to the forum and have already a question >.<

    First of all,


    A little introduction, (hope its not totally out of topic), i am a student at Lisbon at the Faculty of Science of the University of Lisbon, takin a degree in software engeneering. I am 22, and thats about it :P

    Now for the lame question, and yes it must be lame eh:

    I am doing a server/client in C, using TCP, now i know i cant send directly C structs cause of the architecture alignment resctrictions (the pads and all). After some search i came along the way to resolve this, it was:

    1) rearrange structure members;
    2) Serialize structures by-member.

    The big question (and yes i am kinda noobies in C (and the rest for that matter)), how do i do this?

    by no mean i want a sample of code or anything, but if someone could explain how to do this.

    Hope not to bother
    Rykaerdoe <(^.^<) <--- lol taken from FFXI
    sigh - edited cause of grammar lol
    Last edited by Rykaerdoe; 11-24-2004 at 03:02 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
           #include <netinet/in.h>
           uint32_t htonl(uint32_t hostlong);
           uint16_t htons(uint16_t hostshort);
           uint32_t ntohl(uint32_t netlong);
           uint16_t ntohs(uint16_t netshort);
    Take each member of the structure, use the appropriate host-to-network function, send the result over the network, use the appropriate network-to-host function at the other end.

    Or take each member of the structure and format according to these rules

    Or sprintf() each member of the structure into a string, send the string, then sscanf() at the receiver to recover the data.

    Or ....

  3. #3
    Registered User
    Join Date
    Nov 2004
    Thank you so much >.<
    will post how it goes

Popular pages Recent additions subscribe to a feed