Re: Can somebody explain #00#00#00#01 to me? (re: sockets and opcodes)



<jklimek@xxxxxxxxx> wrote in message
news:1130005757.583371.45840@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I've trimmed the newsgroups a bit. Nobody likes over-crossposting, and
Borland also have the right and the means to do something about it.


> I'm trying to write a somewhat simple network application and I've been
> reading the thread here: <Google Groups URL>
>
> In that thread, the author talks about using opcodes to indicate the
> message (eg. packet) type, followed by the size of the message
> (integer), and finally the actual message.
>
> I completely understand the idea behind this, but I'm confused why he
> uses #00 #00 #00 #01 to indicate "opcode #1". He says that the "first
> four bytes" are the opcode (eg. #00#00#00#01) but why not just use an
> integer = 1?

Because he's lazy and doesn't want to write two send operations.


> Does #00#00#00#01 somehow convert into an integer?

Yes. Poorly.

It's four bytes, three zeroes and a one. If read as an integer, this
would be a 32-bit value one in big-endian order. It's customary to
use big-endian order on the wire.

If he cared about code clarity at all, he'd use htonX functions and
use integers where he meant to use integers. As I said, lazy. He's
now managed to confuse at least one person who doesn't know networking
as well as he does. Poor teaching practice. (I do wonder who I've been
insulting now.)

Groetjes,
Maarten Wiltink


.



Relevant Pages