Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Start Page x Client.java x ls Server.java x ticGame java x Source History 16 pub

ID: 3833869 • Letter: S

Question

Start Page x Client.java x ls Server.java x ticGame java x Source History 16 public class Server 17 private static final int portNumber 2000; private static final String welcome Message Server waiting on port" port Number private ServerSocket the Server; 20 21 public static void main string Clargs) 22 new Server Start 23 24 el private void start 25 26 27 try the Server new Server Gocket port 20 System out.println. welcome Message) 29 while (true) 30 Creates a new game 31 ticGames game new tic Game Client client new Client (the accept "X", game t1 22 Client client2 new client (theServer ccept "o", game 34 client .set oppositeplayer (client2) 35 client 2. setoppositePlayer (client1) 36 game .waitTurn ient1 37 new Thread (client1 start 38 new Thread (client2 start 39 40 41 42 catch (IOException e l 43 e-print StackTrace finally 46 try the server.close ();1 catch (IOException e) f e printstackTrace 48 49 50 51

Explanation / Answer

Hi,

I have edited the client.java code wherein the constructor runs.

A new line has been added to create the client socket also where the client will listen.

The modification done can be seen in bold.

CODE:-

==============================================================================

private PrintWriter output;
private static final int portnumber=2000;

public Client (Socket clientSocket,String XO,ticGame game)
{
this.clientSocket=clientSocket;
this.XO=XO;
this.game=game;
/* this will create client socket using the same port number which server is listening*/
Socket socket = new Socket(clientSocket, portnumber);
input=new BufferedReader(new InputStreamReader(socket.getInputStream()));
output=new PrintWriter(socket.getOutputStream(), true);
output.println("you are"+XO);
}

===================================================================================

Please let me know in case of clarification.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote