1130 Networking: Streams-Based Sockets and Datagrams Chapter 22 (Ipower web hosting)

1130 Networking: Streams-Based Sockets and Datagrams Chapter 22 197 // display on the server that a connection was made 198 server.Display( “Player ” + ( number == 0 ? ‘X’ : ‘O’ ) 199 + ” connected” ); 200 201 // send the current player’s mark to the server 202 writer.Write( mark ); 203 204 // if number equals 0 then this player is X, so send 205 writer.Write( “Player ” + ( number == 0 ? 206 “X connectedrn” : “O connected, please waitrn” ) ); 207 208 // wait for another player to arrive 209 if ( mark == ‘X’ ) 210 { 211 writer.Write( “Waiting for another player” ); 212 213 // wait for notification from server that another 214 // player has connected 215 lock ( this ) 216 { 217 while ( threadSuspended ) 218 Monitor.Wait( this ); 219 } 220 221 writer.Write( “Other player connected. Your move” ); 222 223 } // end if 224 225 // play game 226 while ( !done ) 227 { 228 // wait for data to become available 229 while ( connection.Available == 0 ) 230 { 231 Thread.Sleep( 1000 ); 232 233 if ( server.disconnected ) 234 return; 235 } 236 237 // receive data 238 int location = reader.ReadInt32(); 239 240 // if the move is valid, display the move on the 241 // server and signal the move is valid 242 if ( server.ValidMove( location, number ) ) 243 { 244 server.Display( “loc: ” + location ); 245 writer.Write( “Valid move.” ); 246 } 247 Fig. 22.5 Fig. 22.FiFig. 22.5g. 22.5Server side of client/server Tic-Tac-Toe program. (Part 5 of 6.) Fig. 22.5
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp web hosting services

Leave a Reply