Reference no: EM132640466
NET4005 Network Applications
Assignment - 1: Socket Programming and Concurrency
Objective:
Objective of this assignment is to write a simple client-server network application using Java socket programming API. Also, to learn simple concurrency control techniques in a multithreaded program.
Description:
You will write a client-server java program for transferring some file from the server to the client. The server and the client are separate programs and may be running on different computers.
The server program runs and waits for requests from the client. The client program takes a file name X as a command line parameter and asks the server if it has the file X. After receiving the request, the server checks if the file X is in its current directory and lets the client know. In addition, the server tells the client some statistics regarding the visits by all previous clients. Specifically, the server sends 2 numbers <N, M>, where N is the total number of requests so far and M is the number of successful requests. The statistics include the current request, and the server must update the statistics at every request. After the initial response, if the file was available the server sends the file to the client.
The client program displays three pieces of information it receives from the server - whether the file was found, and the two numbers M and N. If the file X was found then the client receives the file from the server and stores it in the current directory. After file transfer is complete, the client displays the message "file transfer complete" and terminates. The server program keeps running forever, and displays a log of current request (including client IP address and the requested file) and the statistics.
You must design the necessary protocol such that the information exchange between the client and the server works properly.
Implementation details:
Implement the client and the server as separate java programs, myfileclient.java and myfileserver.java, each having a main() method (you may have other classes in both the server and the client programs). The server must be able to handle concurrent requests from multiple clients, without holding requests for a long time. To do this, the server should handle the requests using a pool of worker threads. While there can be 100s of clients requesting files to the server, the server is restricted to have 10 worker threads only. After receiving requests from a client, the server will store this request in a queue. All the worker threads start running from the beginning. A worker thread can serve one client request at a time. Whenever a worker thread finishes serving a client request, it picks up the next available request from the queue and start serving that. Note that when multiple worker threads update the statistics M and N, you must be careful about having correct values.
User interface:
The client program is run as:
java myfileclient <server_IP> <server_port> <filename>
Output of the client program:
File <filename> [not] found at server
Server handled <N> requests, <M> requests were successful Downloading file <filename> // if the file found
Download complete // if the file found
The server program is run as:
java myfileserver
Output of the server program (for every request):
REQ <N>: File <X> requested from <IP> REQ <N>: [Not] Successful
REQ <N>: Total successful requests so far = <M> REQ <N>: File transfer complete
Attachment:- Socket Programming and Concurrency.rar