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

This is a discussion on New to the forum and have already a question >.< within the C Programming forums, part of the General Programming Boards category; First of all, Hi A little introduction, (hope its not totally out of topic), i am a student at Lisbon ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    10

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

    First of all,

    Hi

    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 02:02 PM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    Code:
           #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
    http://www.faqs.org/rfcs/rfc1014.html

    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
    Posts
    10
    Thank you so much >.<
    will post how it goes

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21