This lab is designed to help you in your programming project.
-
Make sure to download and install JDK, from Oracle
-
To check if you have already JDK installed, go to the terminal and type
javac
-
Download EchoServer.java (from blackboard or here and EchoClient.java (from blackboard or here)
-
Open two terminal screens.
-
Go to the directory that has the downloaded files. "
cd
" Assume the directory is "c:\users\user\Downloads\network", You may type: cd "c:\users\user\Downloads\network" in the terminal. Note For more check out this for Windows, and this for MacOS. -
In the first terminal window, type:
javac EchoServer.java
-
To run the server, type:
java EchoServer 9000
, here the port we use is 9000 -
In the second terminal window, type:
javac EchoClient.java
-
To run the client, type:
java EchoClient 127.0.0.1 9000
-
What ever you type in the client, it will be sent to the server and back to the client.
-
Open a new terminal, and run another client.
-
However, it would not work. Because the socket is already occupied with the other client.
-
To solve this issue, you need allow multiple clients. To do that we need to change the server.
-
Download the following two java files: EchoServerThread.java and EchoServer2.java
-
Compile them, using
javac EchoServer2.java
& andjavac EchoServerThread.java
-
The updated server allows multiple clients. To run it, using java EchoServer2 9000' NOTE Make sure to close the other server, you can use
ctrl+c