O'Reilly logo

Head First Java, 2nd Edition by Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 15. Networking and Threads: Make a Connection

image with no caption

Connect with the outside world. Your Java program can reach out and touch a program on another machine. It’s easy. All the low-level networking details are taken care of by classes in the java.net library. One of Java’s big benefits is that sending and receiving data over a network is just I/O with a slightly different connection stream at the end of the chain. If you’ve got a BufferedReader, you can read. And the BufferedReader could care less if the data came out of a file or flew down an ethernet cable. In this chapter we’ll connect to the outside world with sockets. We’ll make client sockets. We’ll make server sockets. We’ll make clients and servers. And we’ll make them talk to each other. Before the chapter’s done, you’ll have a fully-functional, multithreaded chat client. Did we just say multithreaded? Yes, now you will learn the secret of how to talk to Bob while simultaneously listening to Suzy.

Real-time Beat Box Chat

image with no caption

You’re working on a computer game. You and your team are doing the sound design for each part of the game. Using a ‘chat’ version of the Beat Box, your team can collaborate—you can send a beat pattern along with your chat message, and everybody in the Beat Box Chat gets it. So you don’t just get to read the other ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required