Efficient Client-Client Communication Through Channels

In some cases you want to send information from one client to another client. For example, you might provide chat communications between clients on the same team, or all players in the same room in a MMORPG. Using the communication methods previously discussed, all of these communications would have to first be sent into the server and then broadcast back out to the appropriate other clients. This approach makes the server a single bottleneck in communication. In general, your game server has much better things to do with its CPU resources than relay communications from one client to another. A more efficient approach is to have clients communicate directly with each other. In Darkstar, this direct communication is provided by channels. Channels provide a publish/subscribe paradigm for communication. Clients are subscribed to one or more named channels. A client can then send arbitrary messages to the channel. Any message sent by a client to a particular channel is received by all of the other subscribers to the channel. The sender does not receive a copy of his own message. A comparison between Darkstar's two different communication methods are shown in Figure 5.

Comparing Client 2 sending a message to Clients 1 and 3 using direction communication through the server or channel communication

Figure 5. Comparing Client 2 sending a message to Clients 1 and 3 using direction communication through the server or channel communication

In Darkstar, channels are created ...

Get Darkstar: The Java Game Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.