Java: Intro. to Prob. Solv... (Looseleaf)
Java: Intro. to Prob. Solv... (Looseleaf)
7th Edition
ISBN: 9780133841084
Author: SAVITCH
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 10.6, Problem 35STQ

Explanation of Solution

 Modified program:

 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...

Blurred answer
Students have asked these similar questions
Topic: Data Communication & Network 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: Creating 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 {…
How does a server know that one of the far-off objects he gives his clients could be collected since it is no longer in use?
I need the Server code written in Python for the given client code. A sample working client code is given to you in Client.py.  I need a corresponding Server code. The goal of the server is to get any string sent to it, and switch any letters from lower case to capital and vice-versa. Lastly it should then close gracefully when the client is done sending strings. The client code is provided below: import argparse from sys import argv import socket #First we use the argparse package to parse the aruments parser=argparse.ArgumentParser(description="""This is a very basic client program""") parser.add_argument('-f', type=str, help='This is the source file for the strings to reverse', default='source_strings.txt',action='store', dest='in_file') parser.add_argument('-o', type=str, help='This is the destination file for the reversed strings', default='results.txt',action='store', dest='out_file') parser.add_argument('server_location', type=str, help='This is the domain name or ip address…

Chapter 10 Solutions

Java: Intro. to Prob. Solv... (Looseleaf)

Ch. 10.3 - Prob. 11STQCh. 10.4 - Write some Java code to create an output stream of...Ch. 10.4 - Give three statements that will write the values...Ch. 10.4 - Give a statement that will close the stream toFile...Ch. 10.4 - What import statement(s) do you use when creating...Ch. 10.4 - Prob. 16STQCh. 10.4 - Give three statements that will read three numbers...Ch. 10.4 - Give a statement that will close the stream...Ch. 10.4 - Can you use writeInt to write a number to a file...Ch. 10.4 - Can you use readUTF to read a string from a text...Ch. 10.4 - Prob. 21STQCh. 10.4 - Prob. 22STQCh. 10.4 - Does the class FileInputStream have a method named...Ch. 10.4 - Does the class FileOutputStream have a constructor...Ch. 10.4 - Does the class ObjectOutputStream have a...Ch. 10.4 - Prob. 26STQCh. 10.4 - Suppose that a binary file contains exactly three...Ch. 10.4 - The following code appears in the program in...Ch. 10.4 - Prob. 29STQCh. 10.5 - Prob. 30STQCh. 10.5 - Prob. 31STQCh. 10.5 - Prob. 32STQCh. 10.5 - Prob. 33STQCh. 10.6 - Prob. 34STQCh. 10.6 - Prob. 35STQCh. 10.6 - Prob. 36STQCh. 10.6 - Prob. 37STQCh. 10 - Write a program that will write the Gettysburg...Ch. 10 - Modify the program in the previous exercise so...Ch. 10 - Write some code that asks the user to enter either...Ch. 10 - Write a program that will record the purchases...Ch. 10 - Modify the class LapTimer, as described in...Ch. 10 - Write a class TelephoneNumber that will hold a...Ch. 10 - Write a class contactInfo to store contact...Ch. 10 - Write a program that reads every line in a text...Ch. 10 - Repeat the previous exercise, but write the new...Ch. 10 - Write a program that will make a copy of a text...Ch. 10 - Suppose you are given a text file that contains...Ch. 10 - Suppose that you have a binary file that contains...Ch. 10 - Suppose that we want to store digitized audio...Ch. 10 - Write a program RecoverSignal that will read the...Ch. 10 - Even though a binary file is not a text file, it...Ch. 10 - Write a program that searches a file of numbers...Ch. 10 - Write a program that reads a file of numbers of...Ch. 10 - The following is an old word puzzle: Name a common...Ch. 10 - The Social Security Administration maintains an...Ch. 10 - The following is a list of scores for a game....Ch. 10 - Write a program that checks a text file for...Ch. 10 - Prob. 5PPCh. 10 - Prob. 6PPCh. 10 - Revise the class Pet, as shown in Listing 6.1 of...Ch. 10 - Write a program that reads records of type Pet...Ch. 10 - Prob. 9PPCh. 10 - Prob. 12PPCh. 10 - Prob. 15PP
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education