Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, you define how the packet will look - what information will be in it. Make sure the definition is in an architecture-neutral format. That means that you specify it in a sequence that does not depend on whether the machine is big-endian or little-endian, for example, nor on whether you are compiling with 32-bit <code>long</code> or 64-bit <code>long</code> values. If the content is of variable length, make sure the definition contains the information needed to tell how long each part is - in particular, each variable length part should be preceded by a suitable count of its length.</p> <p>When you need to package the data for transmission, you will take the raw (machine-specific) values and write them into a buffer (think 'character array') at the appropriate positions, in the appropriate format.</p> <p>This buffer will be sent across the wire to the receiver, which will read it into another buffer, and then reverse the process to obtain the information from the buffer into local variables.</p> <p>There are functions such as <code>ntohs()</code> to convert from a network ('n') to host ('h') format for a 'short' (meaning 16-bit) integer, and <code>htonl()</code> to convert from a host 'long' (32-bit integer) to network format - etc.</p> <p>One good book for networking is Stevens' "<a href="http://unpbook.com/" rel="nofollow noreferrer">UNIX Network Programming, Vol 1, 3rd Edn</a>". You can find out more about it at its web site, including example code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload