Explanation of Solution
Modified
The below highlighted parts are the modified codes in the server and client programs.
Server program:
//import required header files
import java.util.Scanner;
import java.io.InputStreamReader;
import java.io.DataOutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.ServerSocket;
//definition of "SocketServer" class
public class SocketServer
{
//definition of main method
public static void main(String[] args)
{
//declare the objects for the classes
Scanner inputStream = null;
PrintWriter outputStream = null;
ServerSocket serverSocket = null;
//try block
try
{
// wait for connection on port 6789
System.out.println("Waiting for a connection.");
serverSocket = new ServerSocket(6789);
Socket socket = serverSocket.accept();
// connection made, set up streams
inputStream = new Scanner(new InputStreamReader(socket.getInputStream()));
outputStream = new PrintWriter(new DataOutputStream(socket.getOutputStream()));
//get the input from the client
int i = inputStream.nextInt();
int j = inputStream.nextInt();
//send the output to the client
outputStream.println(i + j);
//flush the stream
outputStream.flush();
//display the statement
System.out.println("The connection is closed ");
//close the connections
inputStream.close();
outputStream.close();
}
//catch block
catch (Exception e)
{
// display the exception
System.out.println("Error " + e);
}
}
}
Client program:
//import required header files
import java...
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Java: Intro. to Prob. Solv... (Looseleaf)
- In this assignment you will develop a client-server application. The client will send the server an integer number to see whether the number is a prime number or not. The server will test the number and tell the client the result. You have to write a client code and a server code for the project using either UDP or TCP socket programming. Can I have this prime number program code in C++ or java with detailed explaination and outputs please? Can you make sure to input the prime number during the compilation. Thank youarrow_forwardWrite a server for a client. The client sends loan information (annualinterest rate, number of years, and loan amount) to the server (see Figure a).The server computes monthly payment and total payment, and sends them back tothe client (see Figure b). Name the client Exercise33_01Client and the serverExercise33_01Server.arrow_forwardHow does a server know that one of the distant objects he has made available to clients is no longer in use and is therefore available for collection? What options exist and how is this problem handled by Java RMI?arrow_forward
- Write a Java application for a server that listens to a client. The server should run on port 4999. Once the server is running it should output “Server is starting….”, then it should wait to receive a message from the client. Once it receives the message, it should close the socket. Create a client that sends a message to the server through port 4999. The message that should be sent to the server should be the sum of two numbers. Once it sends the message, it should close the socket.arrow_forwardSeparate the server code and client code into two different programs, server.py and client.py. Execute the server program first and then execute the client program. You should still get the same set of print messages as in the combined threaded code in proj.py In the program provided, the server just sends a message string to the client after it connects. In this step you have to modify the server in two cases.1) Modify the server code so that when the client sends a string to the server, the server reverses the string before sending it back to the client. For example, if the client sends HELLO to the server, the client should receive OLLEH. Your client program should print the string sent by the client and the corresponding string received by the client from the server.2) Modify the server code so that when the client sends a string to the server, the server change all letters to upper case letters and sending it back to the client. For example, if the client sends hello to the…arrow_forwardSolve with java : Write a Server-Client application that Server provides the page number information of the requested section in the book while the section is requested by the Client. Part I Write method for searching the page number of the requested section.Part II Write Server side class for waiting Client to ask a section and responding itspage number.Part III Write Client side class for requesting a section from Server.arrow_forward
- Write a Java application for a server that listens to a client. The server should run on port 8250. Once the server is running it should output “Server is starting….”, then it should wait to receive a message from the client. Once it receives the message, it should close the socket. Create a client that sends a message to the server through port 8250. The message that should be sent tothe server should be the sum of two numbers. Once it sends the message, it should close the socket. Figure 2(attached) shows messages from the server:arrow_forwardCreate a simple Client-Server communication via Sockets where Client will send the message in following form → {message, SHA_256_hash_value}. Once the server receives the message it will parse it, calculate the SHA_256 hash value of the message part and compare it with the received hash. If values are matching it will send 'OK' back to Client, else 'Message was compromised'. Use Java GUI to send and receive messages in both parties (client and server).arrow_forwardWrite a Java application for a server that listens to a client. The server should run on port 8250. Once the server is running it should output “Server is starting….”, then it should wait to receive a message from the client. Once it receives the message, it should close the socket. Create a client that sends a message to the server through port 8250. The message that should be sent tothe server should be the sum of two numbers. Once it sends the message, it should close the socket. output: run: Server is starting... Message received from client: 4+3=7arrow_forward
- I do not want the solution on paper, I want the solution in text, pleaseWrite a java program to create a class named ReverServer. A ReverServer listens on port 1099 for incoming connections from client programs. When ReverServer connects to a client it reads one line of text at a time from the client, reverses the characters in the text line, and sends them back to the client.arrow_forwardGiving that the Counter class initializes itself to 0, and allows a client to increment it. Identify the possible output of the following code sequence: Counter c = new Counter(); c.increment(); c.increment(); c.increment(); System.out.println(c); A. 0. B. 1. C. 2. D. 3arrow_forwardWrite a Java application for a server that listens to a client. The server should run on port 8250. Once the server is running it should output “Server is starting….”, then it should wait to receive a message from the client. Once it receives the message, it should close the socket. Create a client that sends a message to the server through port 8250. The message that should be sent to the server should be the sum of two numbers. Once it sends the message, it should close the socket. Figure 2 shows messages from the server:arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education