A network simulation is maintained by exchanging data among the hosts. Instead of sending messages willy nilly, most applications send them in well-defined patterns, called models. There are several common network models:
* Broadcast: Hosts exchange messages directly with each other.
* Client/Server: All messages are exchanged through one host.
* Token Ring: Each host exchanges messages in sequential order.
* Two Player: Two hosts exchange messages with each other.
Unfortunately, things aren't quite that simple. The design of a networked simulation should be broken into two interdependent layers: the topology and authority. The network topology determines how data are sent from one host to another (routing messages). The authority model dictates how state changes are coordinated among multiple hosts (synchronizing state).
This distinction is often understated or ignored when planning a network simulation. Of course, it's not absolutely necessary to enforce the separation, and many designers find it convenient to use the same model for both the topology and authority -- but you should at least understand the differences. As you read each description, notice how the model applies to each layer.
Finally, this is only a brief introduction and comparison of each networking model. Future articles will describe the design and implementation of each one in greater detail.
[Broadcast] Broadcast
In this simple network model, each host sends each message directly to all of his peers. A broadcast topology requires that each host exchange messages with every other host (no firewalls, no proxies, no bridges). This authority model is called peer-to-peer because each host is the authority for his agent and resources -- informing his peers of state changes and listening for theirs.
This naive approach to networking sacrifices bandwidth for lower latency. Each host sends and receives a large number of packets, causing packet loss at routers and on the wire. It's also more work to process and synchronize data from other hosts. While latency is reduced by design, the increased network traffic makes this model unsuitable for anything but local-area games -- which don't suffer from latency anyway.
[Client/Server] Client/Server
A server is the host selected to administrate the networking. In the client / server topology, clients connect to the server and send it all their data to for handling or routing. When the authority model is client / server, the clients defer decision-making and other game logic to the server. In some designs, the server is simply a dedicated process on a well-advertised host that performs routing or decision making without actually participating in the game.
Internet games prefer this model for two very basic reasons: performance and simplicity. Since messages are only sent to the server, both bandwidth and latency depend on the link quality between the client and server. Also the server is the sole authority and runs the bulk of the simulation, so clients don't need much game logic -- they can even be "dumb terminals," polling inputs and rendering graphics. Finally, the size of client / server simulations are bounded only by the network and processing power of the server.
[Token Ring] Token Ring
The middle ground between broadcast and client/server, a token ring simplifies network design by restricting the exchange of messages. When a host receives the virtual token (think of the baton in a relay race), it performs all game logic and state changes in a batch and then passes control to the next host. Instead of deferring to a single dedicated server, each host is periodically responsible for forwarding packets or running the simulation.
Because control is passed from host to host, there is no need for a dedicated server -- any host can join or leave the session without disruption. The downside is that token ring networks don't scale very well. Since messages and state changes must pass through every host, simulation speed is dictated by the total latency of the ring. This makes token rings unsuitable for realtime Internet play by more than 4 or 6 hosts, but very nice on small local networks.
[Two Player] Two Player
This design is just a degenerate case of the other three. While the topology consists of simply sending packets between hosts as necessary, the authority model can be almost anything: each host runs his own simulation (broadcast), one host defers entirely to the other (client / server), or each host takes control in turn (token ring).
This model is elegant both because of its simplicity and its size. Once the designer has chosen how authority is divided, the engine is easy to implement. In addition, networking is limited only by the quality of the link between the two hosts, and it's much easier to recover after a catastrophic network break. The obvious drawback is that you only have two players in a game, which just isn't as much fun as a huge deathmatch.
0 komentar:
Posting Komentar