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)
- Python program with unique solution not copied please.arrow_forwardIn Java programming Write the code to print out a customer report. Your code must read each customer from a file, populate the object, place the object in a linked list, and display the data from the linked list. Use the customer object name from Customer customer = new Customer ( “ customer name” ); Assume you have opened a file and read a line into the customer object. Write the signature line for this method Write the line of code that will write the object to a linked list Write the line of code that will print the customer object properties. Be sure to include a textual description of each property.arrow_forwardCreate 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_forward
- Focus on string operations and methods You work for a small company that keeps the following information about its clients: • first name • last name • a 5-digit user code assigned by your company. The information is stored in a file clients.txt with the information for each client on one line (last name first), with commas between the parts. For example Jones, Sally,00345 Lin ,Nenya,00548 Fule,A,00000 Smythe , Mary Ann , 00012 Your job is to create a program assign usernames for a login system. First: write a function named get_parts(string) that will that will receive as its arguments a string with the client data for one client, for example “Lin ,Nenya,00548”, and return the separate first name, last name, and client code. You should remove any extra whitespace from the beginning and newlines from the end of the parts. You’ll need to use some of the string methods that we covered in this lesson You can test your function by with a main() that is just the function call with the…arrow_forwardThere are two java classes called Server and Client that you need to develop. Server class will accept connections from port 8900 and listen for characters coming from the client in a loop. When the "0" (zero) character is received by the client, it will convert all the characters that have come so far into a String and write it to a text file named "incoming_text.txt" (you can use the FileWriter class) and terminate the Server application. The Client class will connect to the Server application that listens to the 8900 port of the computer with the IP number 127.0.0.1 and will transfer each character that the Client user enters one by one from the keyboard (the characters will be taken one by one with the help of a loop) to the Server application one by one. If the client user enters the "0" (zero) character, it will stop receiving input from the user, transmit the "0" character to the Server application and terminate the Client application. The sample console output of the…arrow_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
- Write 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_forwardusing netbean softwarearrow_forwardWrite a game program that prints a chart to the screen showing the randomness of a die. The game should first prompt the client for a number of die throws that he would like. The game then throws the die that many times. The game then prints a chart showing a line of asterisks for each die number, indicating the number of times the die landed with that face number on top. If the die behaves in a truly random fashion, each chart will look a little different, reflecting the randomness of the die. A random die number can be generated with the following code: int diceFaceNumber = (int)((Math.random() * 6) + 1). Allow the client to repeat the game as many times as she wishes. I used six methods to simplify the code. Any group of lines of code that is repeated is a prime candidate for a method. Guarantee the number entered is not less than zero. Recall System.out.print(); does not give a new line and can be used to print a series of asterisks or a string of asterisks can be…arrow_forward
- If wrong answer this time will downvote it Create a class with a static main that tests the ability to resolve and print a Path: • Create an instance of a FileSystem class. • Resolve an instance of a Path interface from a directory path and filename. • Print the constructed Path with System.out.println() method. 2. Create a class with a static main that tests the ability to resolve and print a Path: • Create an array of Path class. • Instantiate instances of Path with absolute and relative paths. • Print the constructed elements of the array of Path class with System.out.println() method. 3. Create a class to test serialisation class that implements serializable, it should implement the following: • A static void method that serialises an object. • A static void method that deserializes an object. • A static main method that tests the two by moving an object from one to the otherarrow_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_forwardWrite a program to produce the first 100 Fibonacci numbers. A Fibonacci number is one that is the product of the prior two generated numbers. The sequence is seeded with the values of 0 and 1, so that the sequence starts off as 01 123. Fibonacci numbers are used in computing hash table locations for file management systems.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