有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

如何在Java中仅通过socket通信实现流控制?

我目前正在使用socket用Java编写一个简单的客户机/服务器。我希望服务器根据通过socket从客户端接收的不同“命令”和/或序列化对象做出决策,反之亦然

比如:

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

使用普通socket通信(可能是序列化)是否有这样的流控制约定?我应该在Java中使用RMI吗


共 (2) 个答案

  1. # 1 楼答案

    我推荐KryoNet做任何RMI类型的事情,而不需要RMI的开销和它带来的不灵活

    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.

  2. # 2 楼答案

    没有。如果使用套接字创建客户机/服务器通信,则必须定义自己的协议以及适用于该协议的规则

    RMI可以通过执行特定的对象方法来简化这一步骤。我最近几年听说的rmi服务器的初始设置等方面的交易并不像过去那样困难

    这里有一个RMI tutorial你可能会觉得有用