Thread: need winsock 2 info...

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    The problem of sending raw structs is one (or two) issues known as

    Endian
    Endianness - Wikipedia, the free encyclopedia

    Alignment
    Data structure alignment - Wikipedia, the free encyclopedia

    Fixing alignment is generally possible with "#pragma pack" kludges and the like.
    Fixing endian is an altogether much harder problem. Typically, you should use the htons() and similar functions to ensure that multi-byte data types are consistently represented on the wire.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Salem View Post
    The problem of sending raw structs is one (or two) issues known as

    Endian
    Endianness - Wikipedia, the free encyclopedia

    Alignment
    Data structure alignment - Wikipedia, the free encyclopedia

    Fixing alignment is generally possible with "#pragma pack" kludges and the like.
    Fixing endian is an altogether much harder problem. Typically, you should use the htons() and similar functions to ensure that multi-byte data types are consistently represented on the wire.
    I was aware of the first issue but the second one took me by surprise.

    These datagrams I'm sending travel only within LAN confines and only between matched client-server pairs. What I seem to be discovering is that data alignment varies even between windows versions... some of the servers on XP some on Windows 7 ... While the whole thing mostly works, I still get the odd time when a smaller datagram isn't sent. (I have "sniffed" it and it is not being sent)

    The pragma doesn't appear to help much as there are still datagrams that don't get sent.

    As is so common in the computer industry I appear to have tripped over convenience here. I'm presently experimenting with different ideas to see which works best...

    Thanks to you also for an informative reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help displaying info from structure
    By kisiellll in forum C Programming
    Replies: 6
    Last Post: 04-04-2009, 12:51 PM
  2. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 08:32 AM
  3. Question about getting an info class from another Form
    By Joelito in forum C# Programming
    Replies: 0
    Last Post: 10-16-2006, 01:02 PM
  4. Help doing an e-mail program in c...
    By Tyler_Durden in forum C Programming
    Replies: 88
    Last Post: 01-02-2005, 03:12 PM
  5. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 12:11 PM