最佳实践:在平台之间通过 TCP/IP 发送对象 [英] Best Practice: Sending Objects over TCP/IP between Platforms

查看:32
本文介绍了最佳实践:在平台之间通过 TCP/IP 发送对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个可以向其他应用程序发送对象的应用程序.

I want to make an application which can send an object to an other application.

一个将在 .NET (C# Winforms) 中开发,另一个将在 Java 中开发..NET 部分将在 Windows 客户端上运行,而 Java 客户端将在资源较少的 Unix 操作系统(如智能手机)上运行.

One will be developed in .NET (C# Winforms) and the other in Java. The .NET Part will be running on a Windows client, while the Java client is running on a Unix OS with low ressources (Like a Smartphone).

我正在寻找最佳实践,以便将这个对象(比如汽车)从我的 .NET 应用程序发送到 Java 应用程序.

I'm looking for the best practice in order to send this Object (lets say Car) from my .NET Application to the Java application.

我想我必须先序列化我的对象,然后发送它,然后我将不得不在 Java 端再次反序列化它.

I guess I have to serialize my Object first, then send it and then I will have to deserialize it again on the Java side.

我的主要标准:

  • 简单,但最重要:漂亮/聪明
  • 通用(如果可能).
  • Easy, but most important: nice/smart
  • Generic, if possible.

我正在考虑序列化我的类 Car 并在另一个平台上具有相同的类结构,只是反序列化它,自动加载属性.

I was thinking of serializing my class Car and having the same class-structure on the other platform just deserializing it, automatically loading the attributes.

应用程序应该这样做.有一个数据库连接到其中一个平台,但这不是我的问题.

The application should just do that. There is a database connected to one of the plattforms, but that's not part of my problem.

我在考虑 JSON 或 XML 序列化,但我不知道这是否是最好/最聪明的方法.

I was thinking of JSON or XML Serializing, but I do not know if this is the best/smartest appproach.

我很高兴有任何建议.

推荐答案

我确实实现了一个跨平台 SSO 框架,该框架使用 JSON 作为特定平台编组解析器之间的通用语言.

I did implement a cross-platform SSO framework that used JSON as lingua franca between platform-specific marshalling parsers.

遵循可交换的命名空间和类名Java 常见做法 为了可读性和名称解析.

Exchangeable namespaces and class names followed Java common practices for the sake of both readability and name resolution.

这个特定实现选择的载体是直接的 TCP/IP 持久连接,但序列化/反序列化层应该完全不可知.

Carrier of choice for this specific implementation was a direct TCP/IP persistent connection, but the serialization/deserialization layer should be completely agnostic about it.

某些细节需要特别注意 - 例如,DateTime 值.为了避免双方的假设,我采用了基于 GMT 0 的 big endian 作为参考格式.集合(数组、列表)也值得关注.

Some specifics needed special care - DateTime values, for example. To avoid assumptions from both sides I adopted GMT 0-based, big endian as the reference format. Collections (arrays, lists) were worthy of attention as well.

这篇关于最佳实践:在平台之间通过 TCP/IP 发送对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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