Skip to content

Latest commit

 

History

History
69 lines (46 loc) · 2.45 KB

File metadata and controls

69 lines (46 loc) · 2.45 KB

Client-Server Architecture

Java Language JUnit5 Testing Framework Maven Dependency Manager

The goal of these programming exercises is to practise:

  • communication with a remote server
  • using the java.net.* package capabilities

For this assignment, we've provided the starter project above.

🌍 Using URLs

Modify App.java to connect to the main CBF website at https://codingblackfemales.com, then read its content line by line and print each line to the screen.

You will need to use HttpURLConnection, BufferedReader and InputStreamReader classes.

Whenever possible, use the try-with-resources construct we saw earlier in the course, and ensure all resources are released.

✅ Verify Your Implementation

To verify that your code works as expected, run the tests. In your terminal, ensure that you are in the root of this repository, then run the following command:

./mvnw clean test

☎️ Client & Server

Create two executable classes:

  • a SocketServer class which uses a ServerSocket to listen for connections on localhost:4040, then prints message it receives on the screen.
  • a SocketClient class which requests a connection to server, sends a simple text message to the server.

Ensure all resources created in your programmes are released appropriately. To test your code manually, you'll need to run each application in a separate terminal:

Terminal 1:

./mvnw compile exec:java -Dexec.mainClass="com.cbfacademy.SocketServer"

Terminal 2:

./mvnw compile exec:java -Dexec.mainClass="com.cbfacademy.SocketClient"

✅ Verify Your Implementation

To verify that your code works as expected, run the tests:

./mvnw clean test

⚠️ IMPORTANT

Due to the nature of the tests needing to bind the same port, it's advisable to run the server and client tests separately until both classes are complete, i.e.:

./mvnw clean test -Dtest=SocketServerTest
./mvnw clean test -Dtest=SocketClientTest