Java Message Lab



Java Message Lab

Setup

On my web page (clipper.ship.edu/~cdgira) is the file Chat.zip. Get it and unpack it in your public_html directory on clipper. It should place all the files in a new directory called chat.

Because the chat program needs a specific port available to get the program to work correctly you will need to make a few changes. These changes are needed as only one program can use a specific port, so it would only work for one of you if you all ran the chat program on the same port.

➢ One of the documents in the chat directory is a class list. Next to each member of the class is the port number assigned to him or her. Look for and find your port number and note it down.

Go into the Chat.html file and look for the JavaScript variable chatPort. Change the value it is set to the to your port number. Also, make sure that chatHost is set to clipper.ship.edu. Make sure and save the changes.

Running

Start the server for the chat program with the command:

java ChatServer

Then navigate to the webpage:

clipper.ship.edu/~/chat/Chat.html

A window should popup (should be in the top-left corner) where you type in your name and click the “Submit” button. In the web browser there is a text field where you can type a message and when you hit enter that message is sent to the server.

Try doing this now.

Now have a friend or neighbor navigate to your web page, login, and have them try and send a message. If all has been setup correctly your web browser should display their message with their name.

Lab Questions

(If you can’t figure out the answer to these you won’t be able to do Project 4)

1. How does the Chat applet know what the values are for the JavaScript variables chatPort and chatHost?

2. What type of java.io streams are used to communicate the messages back and forth?

3. The Chat applet uses an instance of the MessageListener class to send and receive messages. Why is it important that the MessageListener class be a sub-class of Thread?

4. What is the purpose of the ChatServer verses that of the ChatServerConnection?

5. When a message is sent it goes from the Chat applet to the ChatServer, then back to the applet. Determine the path the message takes by listing in order the methods called (and what class they belong to) that move the message from the applet to the server and back to the applet.

6. When you send a message and it displays your chat message in your window it doesn’t attach your name to it. Why?

7. What do you think would happen if two people used the same name when signing in and why?

8. In the MessageListener class the variable m_out occasionally invokes the reset() method. What does the reset() method do and why is this important?

9. You should have noticed by now that there are a lot of try and catch statements indicating that a number of things can go wrong when using this type of communication. List the different types of errors caught during the sending of a message and a little information about each.

10. What allows an instance of ChatMessage to be sent over an object stream?

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download