Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Java; Copy EchoServer.java to SecureServer.java. Copy EchoClient.java to SecureClient.java Modify the Secure*.java files to use Secure Sockets Create a self-signed keystore with password password

Using Java;

Copy EchoServer.java to SecureServer.java.

Copy EchoClient.java to SecureClient.java

Modify the Secure*.java files to use Secure Sockets

Create a self-signed keystore with password password

Verify that your secure client and server can connect and exchange messages

** Below is the EchoServer and EchoClient code to be modified into SecureSever and SecureClient. **

EchoServer:

import java.net.*; import java.io.*;

public class EchoServer { public static void main(String[] args) throws IOException { if (args.length != 1) { System.err.println("Usage: java EchoServer "); System.exit(1); } int portNumber = Integer.parseInt(args[0]); try { ServerSocket serverSocket = new ServerSocket(portNumber);

System.out.println("The server is listening at: " + serverSocket.getInetAddress() + " on port " + serverSocket.getLocalPort());

Socket clientSocket = serverSocket.accept(); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); BufferedReader in = new BufferedReader( new InputStreamReader(clientSocket.getInputStream()));

String inputLine; while ((inputLine = in.readLine()) != null) { System.out.println("I received: " + inputLine);

out.println(inputLine.toUpperCase()); } } catch (IOException e) { System.out.println("Exception caught when trying to listen on port " + portNumber + " or listening for a connection"); System.out.println(e.getMessage()); } } }

EchoClient:

import java.io.*; import java.net.*;

public class EchoClient { public static void main(String[] args) throws IOException { if (args.length != 2) { System.err.println( "Usage: java EchoClient "); System.exit(1); }

String hostName = args[0]; int portNumber = Integer.parseInt(args[1]);

try { Socket echoSocket = new Socket(hostName, portNumber); PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true); BufferedReader in = new BufferedReader( new InputStreamReader(echoSocket.getInputStream())); BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in));

String userInput; while ((userInput = stdIn.readLine()) != null) { out.println(userInput); System.out.println("echo: " + in.readLine()); } } catch (UnknownHostException e) { System.err.println("Don't know about host " + hostName); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to " + hostName); System.exit(1); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions