如果传递 long 类型,32 位客户端如何与 64 位服务器通信? [英] How can a 32 bit client communicate with a 64 bit server if long type is passed?
问题描述
我们有一个在 32 位 Windows 7 上运行的 32 位 C++ GUI 应用程序.我们计划将带有 C++ 应用程序的服务器迁移到 64 位 linux.我们注意到 long 类型在 64 位中更大.这将与从 64 位传递到 32 位的客户端-服务器消息不兼容.有什么好的方法可以解决这种不兼容问题?我们需要更改代码吗?如何?或者我们是否使用第三方软件进行转换?这是什么软件?
We have a 32-bit C++ GUI application running on 32 bit windows 7. We are planning to migrate our server with C++ apps to 64-bit linux. We have noticed that long types are larger in 64 bit. This will be incompatible with the client-server message passing from 64-bit to 32-bit. What is a good way to solve this incompatibility? Do we need to change the code? How? or Do we use a third party software to do the conversion? What software is it?
推荐答案
这就是为什么有标准化的 int32_t
和 uint32_t
类型等,因此您可以根据需要专门选择类型.
That's why there is the standardized int32_t
and uint32_t
types etc., so you could specifically select type depending on your needs.
在您发送的所有结构中将所有 long
类型替换为 int32_t
可能需要很多工作,尤其是如果它是一个大项目,但您(希望如此)只需要做一次.解决这个问题的另一种方法是将数据序列化为文本格式,然后在接收端反序列化,这有很大的好处,它可以使通信几乎完全独立于平台.
It might be quite a lot of work to replace all long
types to int32_t
in all structures you send, especially if it's a big project, but you (hopefully) only have to do it once. Another way of solving this problem is to serialize the data into a text-format and then deserialize it on the receiving side, this has the big advantage that it will make the communication almost completely platform independent.
这篇关于如果传递 long 类型,32 位客户端如何与 64 位服务器通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!