I'm currently considering using java in one of my projects(for reasons unrelated to networking). At the moment I'm using C++ and a custom protocol built on top of UDP. My problem here is that while the added efficiency is nice for sending large amounts of realtime-data, I'd rather have something along the lines of RPCs for pure "logic actions" such as login. RPC's in C++ are hard to do though, since standard C++ itself has no notion of serialization.
我正在考虑在我的一个项目中使用java(出于与网络无关的原因)。目前我正在使用C ++和基于UDP构建的自定义协议。我的问题在于,虽然增加的效率对于发送大量的实时数据很有用,但我宁愿在RPC中使用一些纯粹的“逻辑操作”,例如登录。但是C ++中的RPC很难做到,因为标准C ++本身没有序列化的概念。
In another answer, I found Java's RMI, which seems to be similar to RPCs, but I couldn't find how efficient/responsive it is, nor whether it could be plugged into my existing UDP socket, since I don't want to have two ports open on my server program.
在另一个答案中,我发现了Java的RMI,它似乎与RPC类似,但我找不到它的效率/响应能力,也不能将它插入我现有的UDP套接字,因为我不想拥有在我的服务器程序上打开两个端口。
Alternatively, since I think Java has serialization, I could implement RPC's myself, depending on how straightforward deserializing an arbitrary stream of objects in java is. Still, if this would require me to spend days on learning the intrinsics of java, this wouldn't be an option for me.
或者,因为我认为Java有序列化,我可以自己实现RPC,这取决于在java中对任意对象流进行反序列化是多么简单。尽管如此,如果这需要花费数天来学习java的内在函数,这对我来说也不是一个选择。
3 个解决方案
#1
2
If you're interested in RPC, there is always XML-RPC and JSON-RPC, both of which have free/open-source C++ implementations. Unfortunately, most of my development has been in Java, so I can't speak to how usable or effective they are, but it might be something to look into since it sounds like you have already done some work in C++ and are comfortable with it. They also have Java implementations, so you might even be able to support both Java and C++ applications with XML-RPC or JSON-RPC, if you want to go down that route.
如果您对RPC感兴趣,总会有XML-RPC和JSON-RPC,它们都有免费/开源的C ++实现。不幸的是,我的大多数开发都是用Java编写的,所以我不能说它们的可用性或有效性,但它可能是值得关注的,因为它听起来你已经用C ++完成了一些工作并且对它很熟悉。它们还具有Java实现,因此如果您想沿着这条路线前进,您甚至可以使用XML-RPC或JSON-RPC支持Java和C ++应用程序。
The only downside is that it looks like most of these use HTTP connections. One of the things you wanted to do was to reuse the existing connection. Now, I haven't looked at all of the implementations, but the two that I looked at might not meet that requirement. Worst case is that perhaps you can get some ideas. Best case if that there might be another implementation out there somewhere that does what you need and you now have a starting point to find it.
唯一的缺点是看起来大多数都使用HTTP连接。您想要做的一件事是重用现有连接。现在,我没有看过所有的实现,但我看到的两个可能不符合这个要求。最糟糕的情况是,也许你可以得到一些想法。最好的情况是,如果那里可能有其他实现,那就是你所需要的,你现在有了一个起点来找到它。
#2
1
The use of RPCs as an abstraction do not preclude the use of UDP as the transport layer: RMI is an RPC abstraction that generally used TCP under the hood (last time I looked).
使用RPC作为抽象并不排除使用UDP作为传输层:RMI是一种RPC抽象,通常在底层使用TCP(上次我看)。
I'd suggest just coding up a Java layer to talk your UDP protocol: you can use any one of many libraries to do it and you don't have to discard all your existing work. If you want to wrap an RPC layer around your protocol no reason why you can't do that: create a login
method that sends the login UDP packet and receives the appropriate response and returns it.
我建议只编写一个Java层来讨论你的UDP协议:你可以使用许多库中的任何一个来完成它,你不必丢弃所有现有的工作。如果要围绕协议包装RPC层,没有理由不这样做:创建一个登录方法,该方法发送登录UDP数据包并接收相应的响应并将其返回。
#3
0
If it's a remotely serious project, you should probably take a look at Netty.
如果这是一个远程严肃的项目,你应该看看Netty。
It's a great library for developing networked systems, has a lot of proven production usage and is well suited for things like TCP or UDP client-server communication. I wouldn't go reinventing this wheel unless you really have to :-)
它是开发网络系统的绝佳库,具有大量经过验证的生产用途,非常适合TCP或UDP客户端 - 服务器通信等。我不会去重新发明这个*除非你真的必须:-)
As a bonus they have some good examples and documentation too.
作为奖励,他们也有一些很好的例子和文档。
#1
2
If you're interested in RPC, there is always XML-RPC and JSON-RPC, both of which have free/open-source C++ implementations. Unfortunately, most of my development has been in Java, so I can't speak to how usable or effective they are, but it might be something to look into since it sounds like you have already done some work in C++ and are comfortable with it. They also have Java implementations, so you might even be able to support both Java and C++ applications with XML-RPC or JSON-RPC, if you want to go down that route.
如果您对RPC感兴趣,总会有XML-RPC和JSON-RPC,它们都有免费/开源的C ++实现。不幸的是,我的大多数开发都是用Java编写的,所以我不能说它们的可用性或有效性,但它可能是值得关注的,因为它听起来你已经用C ++完成了一些工作并且对它很熟悉。它们还具有Java实现,因此如果您想沿着这条路线前进,您甚至可以使用XML-RPC或JSON-RPC支持Java和C ++应用程序。
The only downside is that it looks like most of these use HTTP connections. One of the things you wanted to do was to reuse the existing connection. Now, I haven't looked at all of the implementations, but the two that I looked at might not meet that requirement. Worst case is that perhaps you can get some ideas. Best case if that there might be another implementation out there somewhere that does what you need and you now have a starting point to find it.
唯一的缺点是看起来大多数都使用HTTP连接。您想要做的一件事是重用现有连接。现在,我没有看过所有的实现,但我看到的两个可能不符合这个要求。最糟糕的情况是,也许你可以得到一些想法。最好的情况是,如果那里可能有其他实现,那就是你所需要的,你现在有了一个起点来找到它。
#2
1
The use of RPCs as an abstraction do not preclude the use of UDP as the transport layer: RMI is an RPC abstraction that generally used TCP under the hood (last time I looked).
使用RPC作为抽象并不排除使用UDP作为传输层:RMI是一种RPC抽象,通常在底层使用TCP(上次我看)。
I'd suggest just coding up a Java layer to talk your UDP protocol: you can use any one of many libraries to do it and you don't have to discard all your existing work. If you want to wrap an RPC layer around your protocol no reason why you can't do that: create a login
method that sends the login UDP packet and receives the appropriate response and returns it.
我建议只编写一个Java层来讨论你的UDP协议:你可以使用许多库中的任何一个来完成它,你不必丢弃所有现有的工作。如果要围绕协议包装RPC层,没有理由不这样做:创建一个登录方法,该方法发送登录UDP数据包并接收相应的响应并将其返回。
#3
0
If it's a remotely serious project, you should probably take a look at Netty.
如果这是一个远程严肃的项目,你应该看看Netty。
It's a great library for developing networked systems, has a lot of proven production usage and is well suited for things like TCP or UDP client-server communication. I wouldn't go reinventing this wheel unless you really have to :-)
它是开发网络系统的绝佳库,具有大量经过验证的生产用途,非常适合TCP或UDP客户端 - 服务器通信等。我不会去重新发明这个*除非你真的必须:-)
As a bonus they have some good examples and documentation too.
作为奖励,他们也有一些很好的例子和文档。