开发者

How can I implement flow control with just socket communication in Java? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
开发者_如何学Python

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 3 years ago.

Improve this question

I'm currently writing a simple client/server in Java using sockets. I want the server to make decisions based on different "commands" and/or serialized objects that are received from the client via the socket, and vice-versa.

Something like:

[Receive Command 'DoSomething' From Client]
[Call Method 'DoSomething' on the Server]
[Send result/status to Client]
etc...

Is there a convention for flow control like this using ordinary socket communication, perhaps with serialization? Should I be using RMI in Java instead?


I would recommend KryoNet for doing any RMI-type stuff without the overhead of RMI and the inflexibility it brings.

http://code.google.com/p/kryonet/

KryoNet makes the assumptions that it will only be used for client/server architectures and that KryoNet will be used on both sides of the network. Because KryoNet solves a specific problem, the KryoNet API can do so very elegantly.

The Apache MINA project is similar to KryoNet. MINA's API is lower level and a great deal more complicated. Even the simplest client/server will require a lot more code to be written. MINA also is not integrated with a robust serialization framework and doesn't intrinsically support RMI.

The Priobit project is a minimal layer over NIO. It provides TCP networking similar to KryoNet, but without the higher level features. Priobit requires all network communication to occur on a single thread.

The Java Game Networking project is a higher level library similar to KryoNet. JGN does not have as simple of an API.


There is not. If you create client/server communication with sockets, you'll have to define your own protocol and the rules that apply for that protocol.

RMI may ease this step by executing specific object methods. The trade of is, the initial setup for the rmi server etc. which I've heard in recent years is not that hard as it use to be.

Here's a RMI tutorial you may find helpful

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜