使用JAVA和C ++通过Socket发送struct [英] Sending struct via Socket using JAVA and C++

查看:125
本文介绍了使用JAVA和C ++通过Socket发送struct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个套接字,其中服务器在JAVA中,但客户端在C ++中。

I have a socket where server is in JAVA but Client is in C++.

Struct{ 
   float length; 
   char[] name; 
}myStruct;

如何将结构转换为Server发送的字节流,并且客户端可以正确解析?任何示例代码都会有帮助! (我听说XML是一个选项,但我不熟悉它)谢谢。

How can I convert the structures to a byte stream sent by Server and can be correctly parsed by Client? Any sample code would help! (I heard XML is an option but I am not familiar with it ) Thanks.

推荐答案

尝试使用Google的协议缓冲区,托管在 ProtocolBuffers 页面。小巧,高效,python,Java和C ++支持。听起来很适合你的需求。

Try using Google's protocol buffers, hosted at the ProtocolBuffers page at Google Code. Small, efficient, python, Java, and C++ support. Sounds like it suits your needs well.

比XML方法更少的开销,并且比滚动自己更好 - 这比你想象的要难。

Less overhead than an XML approach, and better than rolling your own - it's harder than you'd think.

这篇关于使用JAVA和C ++通过Socket发送struct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆