What is the easiest and most efficient way to combine UDP and RPC in java?

I am currently considering using java in one of my projects (for reasons not related to the network). At the moment I am using C ++ and my own protocol built on top of UDP. My problem is that although the added efficiency is good for sending large amounts of data in real time, I would prefer something according to the RPC for pure โ€œlogical actionsโ€ such as login. RPC in C ++ is hard to do, since standard C ++ itself has no concept of serialization.

In another answer, I found Java RMI, which seems to be similar to RPC, but I could not find how efficient / responsive it was and could not be connected to my existing UDP socket, since I did not want to open two ports on my server program .

Alternatively, since I think Java has serialization, I could implement RPC myself, depending on how straightforwardly an arbitrary stream of objects in java deserializes. However, if it requires me to spend a few days learning Java properties, this will not be an option for me.

+4
source share
3 answers

If you are interested in RPC, there is always XML-RPC and JSON-RPC , both of which have free / open source versions of C ++. Unfortunately, most of my developments were in Java, so I canโ€™t talk about how useful or effective they are, but it may be something that you can look at, since it seems that you have already done some work in C ++ and you like it, They also have Java implementations, so you can even support Java and C ++ applications using XML-RPC or JSON-RPC if you want to go down this route.

The only drawback is that most of them seem to use HTTP connections. One of the things you wanted to do was reuse an existing connection. Now I did not look at all the implementations, but the two that I looked at may not meet this requirement. The worst part is that maybe you can get some ideas. The best case is if there may be another implementation out there somewhere that does what you need, and now you have a starting point for finding it.

+2
source

Using RPC as an abstraction does not preclude using UDP as a transport layer: RMI is an RPC abstraction that usually uses TCP under the hood (the last time I looked).

I would suggest just coding the Java layer to talk about your UDP protocol: you can use any of many libraries to do this, and you don't have to discard all your existing work. If you want to wrap the RPC layer around your protocol, there is no reason why you cannot do this: create a login method that sends a UDP packet for entry and receives the appropriate response and returns it.

+1
source

If this is a remote project, you should probably take a look at Netty .

This is a great library for developing network systems, has many proven manufacturing capabilities and is well suited for things like TCP / UDP client-server. I would not invent this wheel if you really do not need :-)

As a bonus, they also have good examples and documentation.

0
source

Source: https://habr.com/ru/post/1369292/


All Articles