Menu

Need Help Assignment See Instruction Please Pseudo Code Ping Client Appreciate Thank Foll Q43899265

I need help with this assignment. See the instruction below andplease can you do pseudo code too for ping client. I willappreciate that. Thank

The following code fully implements a ping server. You need tocompile and run this code. You should study this code carefully, asit will help you write your Ping client.

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

/*
* Server to process ping requests over UDP. */

public class PingServer {

private static final double LOSS_RATE = 0.3;
private staticfinal int AVERAGE_DELAY = 100; // milliseconds

public static void main(String[] args) throws Exception { // Getcommand line argument. if (args.length != 1) {System.out.println(“Required arguments: port”);
return; }

int port = Integer.parseInt(args[0]);

// Create random number generator for use in simulating //packet loss and network delay.
Random random = new Random();

// Create a datagram socket for receiving and sending UDPpackets // through the port specified on the command line.DatagramSocket socket = new DatagramSocket(port);

// Processing loop. while (true) {

// Create a datagram packet to hold incomming UDP packet.DatagramPacket request = new DatagramPacket(new byte[1024],1024);

// Block until the host receives a UDP packet.socket.receive(request);

// Print the recieved data. printData(request);

// Decide whether to reply, or simulate packet loss. if(random.nextDouble() < LOSS_RATE) {

System.out.println(” Reply not sent.”);

continue; }

// Simulate network delay.
Thread.sleep((int)(random.nextDouble() * 2 * A VERAGE_DELA Y));

// Send reply.
InetAddress clientHost =request.getAddress();
int clientPort = request.getPort();
byte[]buf = request.getData();
DatagramPacket reply = newDatagramPacket(buf, buf.length, clientHost, clientPort);socket.send(reply);

System.out.println(” Reply sent.”); }

}

/*
* Print ping data to the standard output stream. */

private static void printData(DatagramPacket request) throwsException {

// Obtain references to the packet’s array of bytes. byte[] buf= request.getData();

// Wrap the bytes in a byte array input stream,
// so that youcan read the data as a stream of bytes. ByteArrayInputStream bais =new ByteArrayInputStream(buf);

// Wrap the byte array output stream in an input stream reader,// so you can read the data as a stream of characters.InputStreamReader isr = new InputStreamReader(bais);

// Wrap the input stream reader in a bufferred reader,
// so youcan read the character data a line at a time.
// (A line is asequence of chars terminated by any combination of r and n.)BufferedReader br = new BufferedReader(isr);

// The message data is contained in a single line, so read thisline. String line = br.readLine(); // Print host address and datareceived from it. System.out.println(

“Received from ” + request.getAddress().getHostAddress() + “: “+
new String(line) );

}}

Your Job: The Client

You should write the client so that it sends 10 ping requests tothe server, separated by approximately one second. Each messagecontains a payload of data that includes the keyword PING, asequence number, and a timestamp. After sending each packet, theclient waits up to one second to receive a reply. If one secondsgoes by without a reply from the server, then the client assumesthat its packet or the server’s reply packet has been lost in thenetwork.

Hint: Cut and paste PingServer, rename the code PingClient, andthen modify the code.

You should write the client so that it starts with the followingcommand:

   java PingClient host port

where host is the name of the computer the server is running onand port is the port number it is listening to. Note that you canrun the client and server either on different machines or on thesame machine.

The client should send 10 pings to the server. Because UDP is anunreliable protocol, some of the packets sent to the server may belost, or some of the packets sent from server to client may belost. For this reason, the client cannot wait indefinitely for areply to a ping message. You should have the client wait up to onesecond for a reply; if no reply is received, then the client shouldassume that the packet was lost during transmission across thenetwork. You will need to research the API for DatagramSocket tofind out how to set the timeout value on a datagram socket.

Your client will display the reply message from the server alongwith the RTT for each datagram received or a message indicatinglost packet for those not returned within the time limit.

When developing your code, you should run the ping server onyour machine, and test your

client by sending packets to localhost (or, 127.0.0.1). Afteryou have fully debugged your code, you should see how yourapplication communicates across the network with a ping server runby another member of the class.

Expert Answer


Answer to I need help with this assignment. See the instruction below and please can you do pseudo code too for ping client. I wil…

OR