ny of the 3 number from the user, generate a random number between 1 to 3 itself and then apply the Rock Paper Scissors game logic (which is paper beats rock, rock beats scissors, scissors beats paper), Then it will tell the player if the player or server has won. Write another client program to communicate with the server. Kindly make the server in such a way the any time any player can leave and another player can join. Use Java to write the code. *** Reference code: Create a simple Server ***

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Topic: Data Communication & Network

Please provide (.java) file or or direct screenshots from your file as the code doesn't run in the other solutions that have been provided to me previously.

Write a socket server program named "RockPaperScissorsServer", which communicates with players (clients). Server firstly receives a name for the player. Let’s assume 1 is Rock, 2 is Paper and 3 is Scissors. Next Server receives any of the 3 number from the user, generate a random number between 1 to 3 itself and then apply the Rock Paper Scissors game logic (which is paper beats rock, rock beats scissors, scissors beats paper), Then it will tell the player if the player or server has won. Write another client program to communicate with the server.

Kindly make the server in such a way the any time any player can leave and another player can join.

Use Java to write the code.

*** Reference code: Create a simple Server ***

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket;
import java.util.Scanner;

public class Server1 {

private static ServerSocket server = null; private static
Socket socket = null; private static final int port =
8080;
public static void main(String[] args) {

//Create IO Objects BufferedReader in = null; PrintWriter out = null; Scanner consoleInput = new Scanner(System.in);

//Start Server
try { System.out.println("Server is starting ..."); server = new ServerSocket(port); System.out.println("Server has started");
} catch (IOException e) { System.out.println("Can not listen to port: " + port); System.exit(-1);

}
while(true) { //Create Socket
try { socket = server.accept(); System.out.println("Client has been connected\n"); } catch
(IOException e) {
System.out.println("Communication Error with client"); System.exit(-1); }


try { in = new BufferedReader( new InputStreamReader( socket.getInputStream() ) );

out = new PrintWriter(socket.getOutputStream(), true);

out.println("NSU CSE338 LAB Server"); System.out.println("Client Name: " + in.readLine());

while(socket.isConnected()) { System.out.print("Server: "); out.println(consoleInput.nextLine()); System.out.print("Client: "); System.out.println(in.readLine()); }

} catch (IOException e) { System.out.print("Client Left"); consoleInput.close(); } }

}


}

*** Reference code: Creating a Client ***
import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket;
import java.util.Scanner;

public class Client1 {

public static Socket socket = null;

public static void main(String[] args) {

try { socket = new Socket("localhost", 8080);
System.out.println("Connected to Server\n" + "Socket: " + socket.getInetAddress() + ":" + socket.getPort() + "\n" ); } catch (IOException e) { System.out.print("Connection to network can not be stablished"); }

BufferedReader in = null; PrintWriter out = null; Scanner consoleInput = new Scanner(System.in);

try {

in = new BufferedReader( new InputStreamReader(
socket.getInputStream() ));
out = new PrintWriter(socket.getOutputStream(), true);

System.out.println("Server: " + in.readLine()); System.out.print("Client: your name_ ");
out.println(consoleInput.nextLine());

while(true) { System.out.print("Server: "); System.out.println(in.readLine()); System.out.print("Client: "); out.println(consoleInput.nextLine()); }


} catch (IOException e) {
e.printStackTrace();
} } }

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education