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: An Introduction to Problem Solving and Programming (8th Edition)
- Write 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_forwardNeed help with this code: You will write a client-server system for writing/storing notes. Each note has an ID (integer), a title (short text), and a body (long text). A client can have three kinds of requests to the server: upload a note, download a note (given its ID), and search for a note (given a keyword). In the case of search, the server will return a list of IDs and titles of notes whose titles contain the keyword. Design the database to store the notes. Design the Ul of the client. • Write code to implement the system. • You should use design patterns as in the Store Management System: 3-layer; Model-View-Controller; Singleton, Adapter. 1. StoreManager code public class StoreManager { private static StoreManager instance = null; private RemoteDataAdapter dao; private ProductView productView = null; public ProductView getProductView() { return productView; } private ProductController productController = null; public static StoreManager getlnstance() { if (instance == null)…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_forward
- Create a Multi-Client Chat Server using Sockets, Threads & GUI in Java. You should run the Server class first then run multiple Client classes. The output should be as follows: Client Randa Server Server received (Randa) message: Hi Server received (Youssef) message: Hello Server received (Randa) message: How are you? Server received (Youssef) message: I'm fine Server received (Youssef) message: What about you Server received (Randa) message: I'm okay Client Enter name Send (Randa) message: Hi (Youssef) message: Hello (Randa) message: How are you? (Youssef) message: I'm fine X (Youssef) message: What about you (Randa) message: I'm okay Youssef Enter name Send (Randa) message: Hi (Youssef) message: Hello (Randa) message: How are you? X (Youssef) message: I'm fine (Youssef) message: What about you (Randa) message: I'm okayarrow_forwardWhat must the server do to avoid suprises for the client that invokes the Methodarrow_forwardImplementing an arithmetic server using socketsWrite a program with two parts: 1) a client, and 2) an arithmetic server. The job of the client is toaccept input from the keyboard and translate strings that you type into requests to the arithmeticserver. In other words, the client should translate strings such as "3 + 4" into a request to thearithmetic server. There are two versions of this program you have to implement:1. The client and server communicate using UDP.2. The client and server communicate using TCP.You have to submit the following: (a) the client program (b) the server program (c) output showing your program works correctly (you can run both the client and the server on the same computer for generating this output)arrow_forward
- TCP: the client sends only 1 message to the server ‘hello from TCPclient’ and the server responds with the uppercase message. Update the program / make a simple chat program so that The client can send/receive multiple messages to the server. A special exit message is used to disconnect ‘Exit’. Each time client sends a message, the server responds with a confirmation of receiving it and its length. UDP: in the client-side The OS assigns the port number automatically. The client sends a line of characters (data) from its keyboard to the server. Update the client-side of the program so that it takes 2 arguments The port it will bind to. The message that will be sent to the server. Keep the server-side of the program as it is. check the testArg.py --> an example to show you how to use arguments make this 2 socket programming program in python in detail and show the output.arrow_forwardWrite a program that prompts the user to enter a client's account ID, then displays the name of the branch in which this client has an account. The account id is a positive integer composed of 6 digits. An account belongs to Beirut branch if its id starts with 11 An account belongs to Akkar branch if its ld starts with 12 An account id is invalid if it is not composed of 6 digits or it does not start with 11 or 12 Sample run 1: Enter your ID: 114587 It is Beirut Branch Sample run 2: Enter your ID: 3245 Invalid ID Sample run 3: Enter your ID: 311245 Invalid IDarrow_forwardFunction: A client can chat with the server, with input in the screen, and output the other side's replies. No GUI needed. Keypoints: TCP socket is used for both sides. Both sides open two sockets, one for sending, while the other for receiving. IN JAVA OR C/C++ with both client code and server codearrow_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_forwardCreate a java server class that will do the following:• Run on port 8000 and listen to a client• Initially output a “server is starting” message to the screen• Make a connection to the database• Receive product details from the client• Add product details to products table• Send a message back to client to inform whether or not the product was added• Handle any exceptions• Close the server when the user types "stop" on the client side and output a message"Server stopping...." (see Figure 6 attached)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
- 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