Scrabblet A Multiplayer Word Game
Scrabblet is.a complete multiplayer, networked, client server game. It is the most complicated applet in this book, and it handles some of the thorniest issues in Java programming. Scrabblct consists of more than 1,400 lines of code in 11 classes.
Two of these classes arc part of the server side of the applet. The. other nine are downloaded to a web browser and act as the simulation of the game. All of the code elements used in the game have been described in detail in this book. In this chapter we will dissect each class and show how easy using to build a multiplayer game .
NET SECURITY CONCERNS
Most applets on the Net today don't do much with the network after they have been downloaded. One of the reasons is that networking has been made more difficult in Java out of security concerns. Most-lava applet environments, such as Netscape Navigator. and Microsoft Internet Explorer, severely restrict anapplet'suse of the network] This situation is created by TCP lIP's lack of authentication in its most basic protocol". This inherent limitation of the Internet is managed carefully by corporations ·that protect their proprietary data through the use firebox walls, is a computer that sits-between a private network and the rest o( the Internet, All Internet connections flow through it, and i~is able to filter and reject connections and packets, both incomig and outgoing. This way, if a program on the outside of the firewall , attempts to attach to an internal network port, the firewall can block it. If it weren't for ·.the firewall, System administrators would have to audit the security of each machine ' ·on .their internal network. In the case of a firewall-protected network, only the firewall ·needs to be secure, and 'every machine inside is considered "friendly" and left· . unprotected from every other machine inside.
. This is where Java could have posed a security. threat. If java-enabled browsers .
allowed applets to co~ect to arbitrary Internet addresses, then an applet could act as a proxy to some malicious program on the outside of the firewall. Once an applet had been downloaded axlQ automatically run by the web browser.It could then connect to . the neighboring computers and servers. These computers would not expect anything hostile to come an internal computer, so they would accept the connections. The applet would when be free to steal sensitive data and.transmit it back through the firewall to the malicious Internet host. Because of this scenario, applets are only allowed to make network connections to ·exactly one host: the one they were loaded from. This restricts the applet from . snooping around the internal network. One of the many well-publicized "Java security . 'attacks" from researchers at Princeton University was a way of tricking java run-time system into allowing an applen to open network sockets on otherwise forbidden machines. Thankfully, this problem was very difficult reproduce and has subsequently been addressed . What does security have to do with a multiplicity game? Plenty. The easiest way to program a multiplayer game would-be to have the players communicate directly with each other, in a "peer-to-peer" network. This way, playing the game would hot rely on having any particular server software running. Unfortunately, the applct is only ab le to connect back to the server that it was loaded from. This means that two players have to communicate all of their messages to each other via the server . . In this chapter, you will see the source code to a simple server, which manages a list of Ct Liechtensteiner and passes messages between those clients. For the most part, this server knows nothing about the game being played. It just passes 'the messages blithely from point A to point B. This function is handled by two classes, Server and '
Client Connection. They will be described at-the-end of this chapter.