Networking: Game2D Code Study

Tom Kelliher, CS 245

Oct. 29, 2008

Administrivia

Announcements

Deliverables due today, Monday.

Assignment

None.

From Last Time

Threads Lab II.

Outline

  1. Hints for developing network code.

  2. Game2D code study.

Coming Up

Networking Lab.

Hints for Developing Network Code

  1. Suggested ports to use for game development:
    1. d0d0: 52000-52015.

    Should you need off-campus access, establish a VPN connection.

  2. Sun's AppletViewer's implementation of the Socket library leaves much to be desired. And you have to use the policytool to seriously weaken Java's security model.

    Do not use IE with its native JVM to run client code. Firefox and IE with Sun's JVM will work. See class Web site for link to Sun's Java JRE.

    Using the AppletViewer from Eclipse should be fine -- all security is disabled!

    What you'll need to do: Serve your applet from Apache on phoenix. Java's security model permits an applet to connect back to the server which served it.

    Client and server must ultimately reside on phoenix!

  3. If you re-compile your applet for serving from a web server, you must exit and re-start your browser so that it loads fresh versions of the class files.

    How do I make my applet available on the Web?

    1. Create public_html directory under home directory.

    2. Use FileZilla (personal system; install it yourself)or Secure File Transfer Client (lab system) to transfer files to public_html directory.

      Transfer ALL class files.

    3. Use Putty (personal system; again, install it yourself) or Secure Shell Client (lab system) to run the following shell command from your home directory:
      chmod -R go+rX public_html
      

    Skeletal HTML to use:

    <html>
        <head>
            <title>Game2Dclient Applet</title>
        </head>
        <body>
            <h1>Game2Dclient Applet</h1>
            <hr>
            <applet code="Game2Dclient.class" 
                width=500 
                height=500
             >
            </applet>
            <hr>
        </body>
    </html>
    

Game2D Code Study

Source code availability.

Work in your teams to answer the following:

  1. Game2Dclient.java questions:
    1. Each client runs two threads. What are they?

    2. Once the game has begun, what action or actions cause the applet class (line 8) to send a message to the server? What is the format of those messages?

    3. Where in the applet class code is the connection to the server made?

    4. The listen class (line 130) only receives messages from the server. What kinds of messages does it receive? Does it act on those messages directly or indirectly (through a synchronized queue or some other such mechanism.).

  2. G2DLaunch.java questions:
    1. Why is the main class so short (lines 276-282)?

    2. Looking at line 20, explain what the Timer does and how it does it. It may be helpful to have a look at lines 202-204.

    3. Explain how the G2DServer class (line 5) design permits multiple games to occur simultaneously.

    4. Three server threads are required per game. What are they?

    5. What are the main responsibilities of the Game2D class (line 56)?

    6. In line 43, why is the server connecting to itself? Isn't that illegal in Maryland?

    7. Do the ThreadedEchoHandlers (line 137) communicate directly with the two clients or indirectly (using another thread or each other as agents)?

    8. Why is the sky blue?

  3. General question: Where are potential synchronization problems?



Thomas P. Kelliher 2008-10-27
Tom Kelliher