




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





This week, you will begin work on a project we will complete next week, the construction of your own IM chat cli- ent. The program you develop this week will have several limitations. For example, all chat messages you send to or receive from others will be displayed in a single window. Next week, we will address these limitations. This week’s lab will have two distinct parts. First we will ask you to complete a tutorial that introduces more of the features BlueJ provides to help you debug programs. Then, we will ask you to work on the development of an IM client. The debugging tutorial is not included in this handout, but instead is listed separately on the course web page.
You should always prepare for lab by carefully reading the lab assignment and sketching out both the code you will write and your plan for implementing and testing various components of the complete program. This week, there is also something a bit more mundane you should do as part of your preparation. As you develop your IM client, you will need to periodically test the code you have written by exchanging messages with another IM client. Once your programs are working fairly well, it will be possible (and maybe even enjoyable) to do this by exchanging messages with other students in the lab or with friends who are nowhere near our lab. Early on in the process, however, it will be much simpler if you can exchange messages with yourself by running a standard IM client on your machine at the same time you are testing your own IM program. All the Macs in our lab have Apple's IM client, iChat, and the standard AIM AOL client installed. So, you will be able to start up AIM or iChat, then start your program and send messages back and forth from one side of your computer screen to the other between the two programs. Note: If using iChat as the other end of the connection, you need to be logged in to iChat using an AOL screen name (as opposed to a .MAC screen name). To do this, you will have to log in with different screen names on your IM program and on the other IM client you use. Accordingly, if you don't already have more than one IM screen name, we would suggest you register for two additional IM accounts before coming to lab. For one of these accounts, choose a screen name that does not contain any blanks or capital letters. For the other, choose a screen name that contains several blanks and capital letters. You will use this second screen name to test one feature included at the end of the lab. In addition, use a standard IM client to log into each of your accounts and make sure to add the other accounts as buddies. Also, add a few of your usual buddies to the new accounts so that they have at least three or four names in their buddy lists.
A sample of what the program's inter- face might look like is shown on the right. Across the top of the program's win- dow, there are fields used to enter the user's IM screen name and password.
Below these fields are buttons used to log in and out. Obviously, the user is supposed to enter a screen name and password before pressing the log in button. Also, until log in is completed successfully, the buttons for logging out and sending messages are disabled. They should become enabled once the user logs in and then be disabled again upon logout. Next, there is a text field intended to let the user enter a message to be sent to one of his or her buddies. Below this there is a pop-up menu labeled “Buddy Name”. The menu is intended to include the names of the user’s buddies. This menu will initially be empty. The processes used to add buddy names to the menu are described below. Once a message has been entered and a buddy selected from the buddy menu, the user can send the message by clicking on the “Send Message” button. In addition, to provide a more convenient interface, your program should also send a message if the user presses the return key while typing in the message field. Immediately below these items, there is a text area that occupies about half the program window. This area is used to display the messages sent between the program's user and his or her buddies. When the program’s user sends a message, the program should display the user’s screen name together with the message in this large text area. Simi- larly, when a message is received from a buddy, the buddy’s name and the message should be displayed. When your program is complete, it will automatically fill the menu before the “Send Message” button with the names of all of your buddies who are currently online. To make your program usable before this feature is imple- mented, we also want you to include a mechanism that will provide a manual way to add names to your buddy menu. At the bottom of your program’s window, there should be a text field labeled “New Buddy Name” and a but- ton labeled “Add Buddy”. Whenever the button is pressed, your program should add the contents of the text field to the buddy menu.
In order to write an IM client, you have to learn a little about the protocol IM clients use to communicate. There are actually several protocols involved. The standard AIM client and other clients that AOL blesses (like Apple's iChat), use a protocol named OSCAR (Open System for CommunicAtion in Realtime). Unfortunately, OSCAR's name is inaccurate. There is nothing “open” about it! OSCAR is a proprietary protocol that AOL guards jealously. Those who write IM clients using OSCAR have to modify them regularly to cope with changes AOL introduces mainly so that non-standard clients stop working. After some complaining, AOL introduced a non-proprietary protocol that can be used to write IM clients. This protocol is named TOC (Talk to OSCAR?). You will be using TOC. TOC is a text-based protocol. All it requires is sending and processing text commands similar to those used in pro- tocols like POP and SMTP. Much like POP and SMTP packets, each packet you send to a TOC server will begin with a code that indicates the type of the message being sent. We will begin by giving an overview of the types of packets your program will exchange with the TOC server. Then, we will discuss the details of the format of the con- tents of these packets. Your program’s interaction with AOL’s TOC server will begin with the transmission of a “toc2_signon” packet that contains both the user’s screen name and password. If AOL accepts this packet, the TOC server will respond by sending a packet that starts with the prefix “SIGNON”. If the screen name or password are invalid, the TOC server will respond with a packet that starts with “ERROR”. One additional packet is required to complete the login proc- ess. If your program receives a “SIGNON” message from the server it must send a “toc_init_done” message in re- sponse. Once your program has completed the login process, it can transmit messages to the user’s buddies by sending “toc2_send_im” packets. Each such packet will contain the body of a message and the screen name of the intended recipient. Unlike POP and SMTP servers, a TOC server will not respond to each such message with a packet indi- cating success or failure. If the message is rejected, the server may send an ERROR packet, but if it is accepted the server will not send any response. When another user sends an IM message to the person using your program, the TOC server will send your program an “IM_IN2” packet containing the message and the sender’s screen name. While you are connected, the TOC server will also send you a variety of other messages. In particular, whenever someone included in the user’s buddy list goes offline, come online, puts up an away message, etc. your program will receive an “UPDATE_BUDDY2” message.
Good Buddies There are a collection of packet types used to manage buddy lists (including things like blocking other users) which we will not consider in this project. There is one packet that provides buddy information that we will find very use- ful. Whenever one of your buddies changes state (i.e. logs on, logs off, puts up an away message, etc.) the server will send your client an “UPDATE_BUDDY2” packet. A sample of the contents of such a packet is shown below: UPDATE_BUDDY2:WSJ:T:0:1127376565:0: O: Each such packet will have seven arguments. The first argument in each UPDATE_BUDDY2 packet will be the screen name of the buddy whose status is being reported. The screen name will not be normalized since this packet is coming from the server. This screen name will be followed by a colon and either a T or an F. A T indicates that the individual with the screen name is now online. An F indicates the individual is not online. If the individual is online, the remaining fields provide details about whether he or she idle or displaying an away message. We will not attempt to describe these other fields in greater detail. Using these packets, you can automatically add and remove names from your program’s buddy menu so that it will contain the screen names of all of your buddies who are actually online. To do this, whenever an “UPDATE_BUD- DY2” packet with a T after the buddy’s name arrives you should add the name to the menu (if it isn’t already there), and whenever an update with an F arrives, you should remove the name from the menu. The tricky part of this is that AOL sends you so many buddy update packets that you are likely to end up with many copies of a buddy’s screen name in your menu if you are not careful. You could avoid this by checking to see if a name is in the menu before you add it. A simpler approach, however, is to simply remove a name before you try to add it. It may seem odd to remove a name without first checking that it is actually in the menu, but the re- moveItem method doesn’t complain if you try to remove an item that isn’t actually there. Make No Mistake One type of packet the server may (regrettably) send to your client is the “ERROR” packet. After the packet type “ERROR”, you will find a colon and one of the following error codes. General Errors 901 -
TOC Sign On packets When a user first connects to the TOC server, your program will have to send a TOC signon packet. An example of what a TOC signon packet looks like is shown below: toc2_signon login.oscar.aol.com 5190 murt74 0x3a060d5c english "TIC:SAIM" 160 98200960 Obviously, these packets are quite ugly! In fact, they are so ugly that we will provide a special class to help you construct them. This class is described below. It will make it unnecessary for you to actually understand the con- tents of a TOC signon packet. For completeness, however, we will still provide a brief description of the fields of a signon packet. As the example above suggests, each signon packet begins with the packet type “toc2_signon”. This is followed by the name and port number for the OSCAR server that the TOC server will use to actual send and receive your message. Next, the packet contains the user’s screenname and password (in a weakly encrypted form). Finally, there are four fields of dubious value. The first specifies the language to be used, but the only supported option is “english”. Next comes a quoted string identifying the name of the client program. Then come two mysterious num- bers. The first is always 160 and not explained by the TOC documentation. The second is derived from the first letters of the user’s screenname and password using a peculiar algorithm about which you need not be concerned. To make it easy to send TOC login packets, we will provide you with a class named TOCSignonPacket. Creat- ing a new TOCSignonPacket requires that you use a constructor of the form new TOCSignonPacket( screenname, password ) The screen name provide should be normalized. There is only one method associated with this class, toString. Invoking this method produces the text of a valid toc2_signon packet for the screen name and password provided in the construction. Therefore, to create a signon packet, you can use instructions of the form: TOCSignonPacket signon = new TOCSignonPacket( screenname, password); String packetContents = signon.toString(); You could then send the string packetContents to the TOC server. While the TOCSignonPacket class makes it unnecessary for you to understand the format of a login packet for this assignment, you will need to know how the server will respond when you send it such a packet. If there is something wrong with the packet, the server will send you one of the “ERROR” packets described above. In this case, you should simply inform the user that the login failed and close your connection to the server. If the information in the login packet is correct, the server will respond by sending a packet that begins with the text “SIGN_ON”. As soon as your program receives such a packet, it should complete the login process by sending the server a packet of the form: toc_init_done Other Server Packets There are several other types of packets the server may send to you including a CONFIG packet that describes all your buddies and buddy groups. You will not need to interpret or process such packets.
Unlike POP and SMTP, TOC is not based directly on TCP. Instead, TOC packets are sent using an AOL-specific protocol named FLAP (no one seems to know what FLAP stands for). The NETConnection class we have used in the last two labs is based on TCP. Therefore, to enable you to work with FLAP, we will provide a new class named FLAPConnection that will enable you to send and receive TOC packets without worrying about the de- tails of the FLAP protocol.
You should plan to add code to implement one feature at a time and to test each feature before moving on to the next step. The following gives an possible plan for such an approach.
As usual, you should start your work by launching BlueJ. BlueJ will open last week’s project by default. You should create a new project with a name that includes “Lab4” and your last name. Remember, do NOT include blanks or special characters in your project name. Then, close last week’s project. Finally, create a new “GUIMan- ager” class with a name like IMClient and start your work.
- GUI layout - Connecting to the server - Disconnecting from the server - Sending IM messages - Receiving IM messages - Manual update of buddy menu - Automatic update of buddy menu - Correctly displaying messages sent and received
The usual rules apply (drop your completed BlueJ project into professor Lawson’s Netfiles Inbox).