For this activity you will submit two java files You will ne

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.

We have seen how two programs can connect. Let’s look more into how they communicate. Once the connection has been made, both sides can establish Data Streams to send information back and forth. There are a few ways to do this. An easy way is by using DataInputStream and DataOutputStream. Using these objects, you can send information in the form of primitive data types back and forth between the Server and the Client.

Two classes are created: a Server and a Client. Both classes create a Socket and they establish a connection. From this point, both classes use the connection to establish Input and Output Streams, and then they can send data back and forth.

Once both classes can send data, your job will be to have the user (always the Client) input a whole number. This number will be sent to the Server, where the Server will calculate the result of squaring that number (raising it to the power of 2), and then it will return the result to the Client where the result will be shown to the user. Finally, everything will close and the connection will terminate.

Summary:

Create a Client class and a Server class

Have the Client connect to the Server

Establish Input and Output Streams for the Server and the Client

Have a user input a whole number on the Client’s side

Send the user’s input to the Server

Have the server calculate the result of squaring the number

Send the result back to the Client

Have the client output the result

Close everything and disconnect

Solution

======Server.java=======

====Client.java=====

====Sample output on client=====

Enter a number: 23
Response from server: 529

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 cap

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site