有一个很好的Java网络库吗? [英] Is there a good Java networking library?
问题描述
我目前正在搜索Java网络库。我想要做的是将XML,JSON或其他序列化消息从客户端发送到另一个客户端和/或客户端到服务器。
我的第一次尝试是创建一个POJO对于每条消息,加上一个MessageWriter用于发送,MessageReader用于接收它。加上套接字和错误处理。这是一个很容易出错的工作。
我正在寻找的是一个从套接字中抽象出来的更高级别的库。此外,它应支持消息的代码生成等内容。
Google的协议缓冲区( http://code.google.com/apis/protocolbuffers/ )看起来很有前景。但有其他选择吗?重点不在于速度或安全性(目前),它应该可靠且工作时间少。
啊......陷阱。
但不是使用代码gen。如果你在两端都有Java,你可以使用简单的对象序列化来编组和取消编组吗?如果需要考虑性能和/或消息大小,可以使Message类可外部化。
之前我没有看过Protobuf。看起来很不错。使用它,你只需要一个传输方法。
I'm currently searching for a Java networking library. What I want to do is sending XML, JSON or other serialized messages from a client to another client and/or client to server.
My first attempt was to create an POJO for each message, plus a MessageWriter for sending and a MessageReader for receiving it. Plus socket and error handling. Which is quite a lot of error prone work.
What I'm looking for is a a higher level library which abstracts from sockets. Furthermore it should supports something like code generation for the messages.
Google's Protocol Buffers (http://code.google.com/apis/protocolbuffers/) looks promising. But are there alternatives? The emphasis is not on speed or security (at the moment), it is just supposed to work reliable and with a low amount of implementation time.
Ah... gotcha. But rather than using code gen. to marshall and unmarshall, if you have Java on both ends, could you use simple object serialization ? If performance and/or message size is a concern, you could make your Message class externalizable.
I had not looked at Protobuf before. Looks pretty decent. Using that, you would then just need a transmission method.
这篇关于有一个很好的Java网络库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!