Question: For this activity, you will submit two .java files. You will need to run two classes simultaneously for this activity. Make sure you have a

For this activity, you will submit two .java files. You will need to run two classes simultaneously for this activity. Make sure you have a compiler that is capable of this.

At this point youve written programs that allow a Server to start and a Client to connect to it. Weve looked at situations in which these programs would be effective ways to work with remote machines, but theres much more that can be done with these kinds of programs.

To really understand the scope of these programs, well have to introduce more users. The biggest reason Server-based programs are so useful are because they are not exclusive to one user. For this program, were going to introduce multiple Clients to the same Server.

This programs Server will start in the same way as the ones youve written so far: it opens a ServerSocket and awaits a connection, but this time with two Clients. The Clients that connect will both be running the exact same code from the same class. To be able to tell which Client will receive what data, the Server will need to keep track of them by creating two different Sockets for the Clients to connect to. In a linear fashion, the Server will accept a connection from two different Clients, and then set up an InputStream and an OutputStream for each one. Using the individual streams, you will then send an ID to each client individually. One Client will receive one ID, and the other Client will receive the other. Both Clients will print out the ID they receive.

Note: Both clients must connect to the Server before the IDs are sent. They must both be connected to the Server simultaneously.

To summarize, your program should do the following:

Create a Server class. This class should have two Sockets; one for each Client.

Create a Client class. This class should be run twice to create two Clients.

Have the Server accept connections from each run of the Client class.

Setup an InputStream and an OutputStream for each Client.

Send an ID to each client these IDs must be unique.

Have the Client print out the ID it received to the console.

Close everything and disconnect both clients.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!