Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help Please this program needs to be done in Java. Help Please 6. Programming As

ID: 3603696 • Letter: H

Question

Help Please this program needs to be done in Java. Help Please

6. Programming Assignment: Based on the content covered in the class, you are required to implement a simplified network client-server simulating program. You can conduct the homework by yourself or work with another student as a group. You are required to set up your system with computers to emulate the sender, receiver and router, which are connected with TCP as shown in the following figure.

Router Sender Receiver Figure 1: Network Transmission Model (Topology)

Figure 1: Network Transmission Model (Topology) The sender will send Y packets (changing Y from 10; 20; 40; 60; 80; 100) via the router to the receiver. The receiver will reply with corresponding acknowledge packet as in the following figure.

We apply the Selective Repeat mechanism for sender and receiver. For the window size, you should use window size equals to 5.

The router in the middle will randomly drop a packet and ACK with a probability (10+X) %, where X is the last digit of the four digit number 9788 and your partners last digit of the four digit number 5973.

We further assume that the router not only randomly drop data packets, but also acknowledge packets.

Router Sender Receiver Figure 1: Network Transmission Model (Topology)

Explanation / Answer

The Java API provides a nice set of libraries for initiating and communicating over TCP/IP sockets. I know a number of Unix programmers (myself included) that had, at one time or another, resorted to writing C or C++ wrappers over the existing BSD sockets API. The standard Unix API provides a very low-level interface, and requires a significant amount of error checking and handling. It is also very architecture-specific. Java, with its java.net package, has removed all of the portability issues, and most of the tedium of network I/O.

However, there is room for improvement. To develop a Java-based server application that listens for client connections and spawns off threads to handle them, a number of steps must be taken. In the following paragraphs, we will go over each of these steps, and will touch on several useful techniques including the use of Sockets, Threads, and basic Java data I/O. The result will be a package that can be used to develop almost any client-server protocol by subclassing the classes in the package. These classes can then be integrated into an applet, or a standalone application.

The architecture

A typical client-server architecture consists of a server application running on one machine, and one or more clients -- often, but not always, operating on different machines across a network. The server is modeled as a perpetual process that waits for clients to connect (request a service), and then processes the client requests. Java threads are ideal to the implementation of a server application, because a new thread can be started for each connecting client. This prevents one client request from holding up others if and when it enters a wait state, or some time-consuming task.

The example - RemoteFileInputStream

For the purposes of this article, we are going to be developing a client-server protocol to allow a client to retrieve a file from the server machine. We will use a familiar API on the client side by mimicking the

java.io.FileInputStream

class in creating the new class RemoteFileInputStream. The constructor will take the hostname of the server, the TCP/IP port number of the service, and the filename to retrieve. The user can then use the methods defined in

java.io.InputStream

to read the data from the file.