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.
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; ...