O'Reilly logo

Java™ How to Program, Seventh Edition by P. J. Deitel - Deitel & Associates, Inc., H. M. Deitel - Deitel & Associates, Inc.

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

24.8. Client/Server Tic-Tac-Toe Using a Multithreaded Server

In this section, we present the popular game Tic-Tac-Toe implemented by using client/server techniques with stream sockets. The program consists of a TicTacToeServer application (Figs. 24.1324.14) that allows two TicTacToeClient applications (Figs. 24.1524.16) to connect to the server and play Tic-Tac-Toe. Sample outputs are shown in Fig. 24.17.

Figure 24.13. Server side of client/server Tic-Tac-Toe program.
 1 // Fig. 24.13: TicTacToeServer.java
 2 // This class maintains a game of Tic-Tac-Toe for two clients.
 3 import java.awt.BorderLayout;
 4 import java.net.ServerSocket;
 5 import java.net.Socket;
 6 import java.io.IOException;
 7 import java.util.Formatter;
 8 import java.util.Scanner; ...

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