Using the Intercom

What does the intercom look like? You start Intercom 1 first (it functions as the server in this pair of applications, so it's necessary to start it first so Intercom 2 can find it), and it appears in Figure 9.1.

Figure 9.1. Intercom 1.

After starting Intercom 1, the person you're going to be typing with starts Intercom 2 on his or her machine, which you see in Figure 9.2.

Figure 9.2. Intercom 2.

How do you connect the intercoms? In Intercom 2, you enter the IP address of Intercom 1 in the text box, as shown in Figure 9.2; that IP address is here, which is what you use if you're testing the two intercoms out on the same machine. If you're running the intercoms on different machines, enter the IP address of Intercom 1 here instead (in fact, even if you run the two intercoms on the same machine, you can enter the broadband IP address of your current machine here, and the two intercoms will connect over the Internet, even though they're on the same machine).

After entering the IP address of Intercom 1 into Intercom 2, click the Connect button in Intercom 2 to connect. If Intercom 1 isn't running, you'll see an error message, as shown in Figure 9.3.

Figure 9.3. Trying to connect to Intercom 1.

If Intercom 1 is out there and ready to roll, Intercom 2 will connect, and you'll see the message "Connected" at the top of Intercom 2, as shown in Figure 9.4.

Figure 9.4. Connected to Intercom 1.

The two intercoms connect using built-in Java classes, with nothing extra needed. Now that you're connected, you can type back and forthyour text goes into the lower text area control, and the other user's into the upper text area. For example, in Intercom 2, you can enter the text "Are you there?" (see Figure 9.5).

Figure 9.5. Entering text to send.

When you click the Send button in Intercom 2, the text you've entered is sent to Intercom 1, where it appears as you see in Figure 9.6. Not badthat text can go across the Internet anywhere in the world, with no Java-enabled ISP needed, no messenger service to sign up with, and no ads to have to look at.

Figure 9.6. Receiving text in Intercom 1.

And, of course, you can enter text in Intercom 1, as you see in Figure 9.7.

Figure 9.7. Entering text to send to Intercom 2.

When you click the Send button in Intercom 1, the text you've entered is sent to Intercom 2, as shown in Figure 9.8.

Figure 9.8. Receiving text in Intercom 2.

And that's itnow you can go back and forth between intercoms, typing what you want. When you do, any new text will be added to the text already typed, as you can see in Figure 9.9, where some new text has been sent by the Intercom 2 user back to Intercom 1.

Figure 9.9. Receiving additional text in Intercom 1.

These intercoms show off a lot of Java's power. Here's what they do:

  • Intercom 1 acts as a server, and it accepts connections from Intercom 2.

  • Intercom 2 acts as a client, and it lets you connect to Intercom 1.

  • When connected, you can use standard Java streams to write back and forth between the intercoms.

When you want to hang up, just close the Intercom windownothing more needed. As you can see, this is one cool application. So how do you create it?

    Java After Hours(c) 10 Projects You'll Never Do at Work
    Java After Hours: 10 Projects Youll Never Do at Work
    ISBN: 0672327473
    EAN: 2147483647
    Year: 2006
    Pages: 128

    Similar book on Amazon © 2008-2017.
    If you may any questions please contact us: