Indy 中 GStack.HostToNetwork 的目的是什么?

What is the purpose of GStack.HostToNetwork in Indy?

我看到 Indy 默认情况下会隐藏必须以某种“网络格式”发送的数据,并在收到时将其转换回来。这样做有什么意义?在套接字的 WriteRead 之间,没有人使用那些只有“我”知道它们的含义的值。那么,位顺序有什么关系呢?我有自己的 TCP 服务器-客户端协议,我将命令的值和我发送的其他内容直接写入临时缓冲区。我想知道通过这些转换使我的协议复杂化是否有意义?

I saw that Indy, by default, coverts data which must be sent in some "network format", and when is received, is converted back. What is the point of doing this ?

并非所有平台都使用相同的字节序来对多字节整数中的字节进行排序。有些平台是小端,有些是大端。为了促进跨平台共享整数,“网络字节顺序”被标准化为 big-endian。因此,HostToNetwork() 会将多字节整数从调用平台的本机端转换为大端,NetworkToHost() 会将多字节整数从大端转换为调用平台的本机端。

Between the Write and the Read from the socket no one uses those values that only "I" know what they means. So, what does it matter the bit order ?

如果您同时编写发送方和接收方,那么您当然可以使用您想要的任何字节序。但是在通过网络连接传输整数时,习惯总是只使用大端。也许有一天,您或其他人会为您的系统编写一个不同的 sender/receiver,甚至可能在另一个平台上。因此,如果您对整数使用标准化的字节序,以后就不必担心互操作性问题。

I have my own TCP Server-Client protocol and I write drectly to a temporary buffer the values of the commands and other stuff I send.

当然,这只有在发送方和接收方使用相同的字节序在内存中表示整数时才有效。

I want to know if it makes sense to complicate my protocol with those conversions ?

进行字节序转换不会使任何事情复杂化,但它确实可以保护它。