Dalvik到Java SE通信(Dalvik to Java SE communications)

编程入门 行业动态 更新时间:2024-10-25 14:33:24
Dalvik到Java SE通信(Dalvik to Java SE communications)

我正在计划开发一款android应用程序,它需要后端服务器与应用程序的其他用户同步数据。 我正计划在Unix服务器上运行的标准Java中编写此服务器。

我曾经直接在两个Android设备之间进行过这种操作,在这种情况下,我只是序列化了需要在两端发送的所有数据。

但是我怀疑Dalvik序列化到的格式和Java SE的格式不兼容。 是这样吗? 如果是,我的替代品是什么? 我想到的一件事是将原始xml发送到套接字上,但如果有更好的选择,我会很乐意听到它们。

谢谢。

I'm planning on developing an app for android that requires a back-end server to sync data with other users of the app. I'm planning on writing this server in standard java running on a unix server.

I once did this directly between two android devices, in that case I just serialized all the data needed to be sent on both ends.

However I suspect that the format that Dalvik serializes to and Java SE's format are not compatible. Is this the case? And if it is, what are my alternatives? One thing that popped into my mind was sending raw xml over a socket, but if there are better alternatives I'll be glad to hear them.

Thanks.

最满意答案

如果你正在做一个服务器,那么你应该依赖像XML或JSON这样更标准的东西。 我个人喜欢JSON。 你不应该期望你的所有客户端都是Java友好的。 几乎每个移动设备都支持JSON。 看看杰克逊图书馆来生成你的json。 然后你可以再次使用Jackson来反序列化你的对象。

这个解决方案的优点也很简单。 只需将请求放入浏览器即可查看内容。 二进制数据不那么容易。

If you are doing a server then you should rely on something more standard like XML or JSON. I personally favor JSON. You shouldn't expect all your client to be Java friendly. Almost every mobile device support JSON. Look at Jackson library to generate your json. Then you can use Jackson again to deserialize your object.

The beauty of this solution is also stupid simple. You can look at the content by just just putting the request in your browser. Not so easy with binary data.

更多推荐

本文发布于:2023-07-15 19:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117751.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通信   Java   Dalvik   communications   SE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!