O'Reilly logo

Killer Game Programming in Java by Andrew Davison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required