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.13–24.14) that allows two TicTacToeClient applications (Figs. 24.15–24.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; ... |
Get Java™ How to Program, Seventh Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.