Starting from:

$30

ECEN MP3 TCP Sockets in Java Solution


    • Introduction

Please read all sections of this document before you begin coding. The purpose of this machine problem is to familiarize you with network programming. Refer to The Java Tutorials [2] for sample code on how to create sockets and send messages using them.

    • Problem Statement

In this assignment, implement a server and a client using Java sockets. The server and client must use a TCP connection to communicate with each other.

Server

The server must have the capability to handle multiple clients simultaneously. The server takes as console input the port number on which clients would connect to it and the maximum number of clients that can connect simultaneously.

>./ s e r v e r <s e r v e r  port> <max .  c l i e n t s >

Upon initialization, the server program asks the user to enter a string (str), e.g., \HelloWorld," and a positive integer (N). Whenever a client is connected to the server, the server transmits str to the client N times, with a one-second pause between transmissions. The rst N-1 transmissions have no end-of-string or newline character at the end. The last transmission ends with a newline character.

Client

The client takes as console input the IP and the port number of the server in order to connect.

>./ c l i e n t <s e r v e r  ip> <s e r v e r  port>

You will write two versions of the client. The rst version, which we call the NaiveClient, displays every character it receives immediately. The second version, which we call the Bu erClient, bu ers all incoming characters and only displays everything when it receives a newline character. Both clients terminate after receiving and printing the newline character.

    • Evaluation Guidelines

        1. Test the correctness with one server and one NaiveClient.

        2. Test the correctness with one server and one Bu erClient.

        3. Test whether the server can correctly serve multiple clients simultaneously. Important: \simultane-ously" is not the same as \one-by-one."




1



References

    [1] Head First Java. HFJ Chapter 15

    [2] http://docs.oracle.com/javase/tutorial/networking/sockets/index.html


























































2

More products