1126 Networking: Streams-Based Sockets and Datagrams Chapter 22 (Web design service)
1126 Networking: Streams-Based Sockets and Datagrams Chapter 22 Fig. 22.5 create an instance of class Player to process the client in a separate thread of execution. This enables the server to handle requests from both clients. The server assigns value “X” to the first client that connects (player X makes the first move), then assigns value “O” to the second client. Throughout the game, the server maintains information regarding the status of the board so that the server can validate players requested moves. However, neither the server nor the client can establish whether a player has won the game in this application, method GameOver (lines 143 147) always returns false. Exercise 22.7 asks the reader to implement functionality that enables the application to determine a winner. Each Client maintains its own GUI version of the Tic-Tac-Toe board to display the game. The clients can place marks only in empty squares on the board. Class Square(Fig. 22.7) is used to define squares on the Tic-Tac-Toe board. 1 // Fig. 22.5: Server.cs 2 // This class maintains a game of Tic-Tac-Toe for two 3 // client applications. 4 5 using System; 6 using System.Drawing; 7 using System.Collections; 8 using System.ComponentModel; 9 using System.Windows.Forms; 10 using System.Data; 11 using System.Net.Sockets; 12 using System.Threading; 13 using System.IO; 14 15 // awaits connections from two clients and allows them to 16 // play tic-tac-toe against each other 17 public class Server : System.Windows.Forms.Form 18 { 19 private System.Windows.Forms.TextBox displayTextBox; 20 21 private byte[] board; 22 23 private Player[] players; 24 private Thread[] playerThreads; 25 26 private TcpListener listener; 27 private int currentPlayer; 28 private Thread getPlayers; 29 30 private System.ComponentModel.Container components = null; 31 32 internal bool disconnected = false; 33 34 // default constructor 35 public Server() 36 { 37 InitializeComponent(); 38 39 board = new byte[ 9 ]; Fig. 22.5 Fig. 22.FiFig. 22.5g. 22.5Server side of client/server Tic-Tac-Toe program. (Part 1 of 6.) Fig. 22.5
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web and email hosting services