Constructing and sending binary data over network

后端 未结 3 1658
走了就别回头了
走了就别回头了 2020-12-15 15:05

I am creating a command-line client for minecraft. There is a full spec on the protocol that can be found here: http://mc.kev009.com/Protocol. To answer your question before

3条回答
  •  被撕碎了的回忆
    2020-12-15 15:33

    For #1, you'll need to use ntohs and friends. Use the *s (short) versions for 16-bit integers, and the *l (long) versions for 32-bit integers. The hton* (host to network) will convert outgoing data to big-endian independently of the endianness of the platform you're on, and ntoh* (network to host) will convert incoming data back (again, independent of platform endianness)

提交回复
热议问题