Server Activities

The processing done by the server is illustrated in Figures Figure 32-6, 32-7, and 32-8, and is of two types:

  • A message arrives and is broadcast to all the other clients.

  • A detailsFor message arrives for a specified client and is routed to that client. This is a client-to-client message.

Broadcasting

The most complex broadcasting is triggered by the arrival of a create message at the server.

Figure 32-6 shows how create fits into the overall activity of creating a new sprite. Figure 32-9 expands the "broadcast create and request for details" box in the server swimlane in Figure 32-6.

Server activities for a create message

Figure 32-9. Server activities for a create message

TourServerHandler is principally concerned with differentiating between the messages it receives. TourGroup handles the two modes of client communication: broadcasting or client-to-client. TourGroup maintains an ArrayList of TouristInfo objects, which contain the output streams going to the clients.

When a create n x z message arrives at the TourServerHandler, it's passed to doRequest(), which decides how to process it (by calling sendCreate()):

    private void doRequest(String line, PrintWriter out)
    {
      if (line.startsWith("create"))
        sendCreate(line);
      else if (line.startsWith("detailsFor"))
        sendDetails(line);
      else  // use TourGroup object to broadcast the message
        tg.broadcast(cliAddr, port, userName + " " + line);
    }

sendCreate() extracts the ...

Get Killer Game Programming in Java 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.