You do NOT have permission to use this code for any commercial purposes without speaking to me to work out a deal.
This program creates a client-router-server TCP LAN connection, requiring 3 different machines. The client streams a file to the router ("server-router"), and the router forwards the file to the server. The router facilitates the client-server streaming using threading, allowing asynchronicity. Any client or server that connects is immediately threaded, allowing multiple pairs of clients and servers to connect. The program outputs the total message size sent by the client, forwarded by the server-router, and received by the server, allowing for verification that the total file was transmitted. Finally, if the file is not a .txt file, the program attempts to open and play the file in JavaFX on both the client and server machines, to verify transmission. At the end of transmission, the client file calculates the total time to make a connection and the total time for the file to be sent and received, and uses this information to calculate the amount of bytes sent per millisecond.
- Delete ServerApp.java and ClientApp.java
- Comment out or delete lines 101-105 in TCPClient.java
- Comment out or delete lines 80-84 in TCPServer.java
To run WITH JavaFX, if wanted: Guide to Install JavaFX in VSCode, if JavaFX is not already installed:
- Download JavaFX from https://gluonhq.com/products/javafx/ for the proper operating system on both the Client and the Server machines.
- Unzip the file.
- In VSCode, under “Java Projects” in the bottom left corner, click “Referenced Libraries,” click the “+” symbol, navigate to the lib folder in the unzipped file, highlight all of the files, and hit enter.
- Go to “Run,” press “Add Configurations,” and in the “launch.json” file, at the bottom after the final “projectName,” add a “,” to the end of the line, press enter, and copy-paste or type the following: "vmArgs": "--module-path "C:/Users/XXX/XXX/javafx-sdk-17.0.2/lib" --add-modules javafx.controls,javafx.fxml,javafx.media"
- Replace the path above with the path to the location of the downloaded JavaFX lib folder.
Knowledge of Java IDE usage and Java code execution is assumed.
- Place ClientApp.java (if using JavaFX) and TCPClient.java on one computer.
- Place ServerApp.java (if using JavaFX) and TCPServer.java on a second computer that is on the same Wi-Fi network.
- Place SThread.java and TCPServerRouter.java on a third computer that is on the same Wi-Fi network.
- Edit TCPClient.java line 13: put the IP of the machine with SThread.java and TCPServerRouter.java on it.
- Edit TCPClient.java line 37: put the file path to the file that you wish for the client to transmit here. This file will be sent to the server.
- Edit TCPClient.java line 43: put the IP of the machine with ServerApp.java and TCPServer.java on it.
- Edit TCPServer.java line 13: put the IP of the machine with SThread.java and TCPServerRouter.java on it.
- Edit TCPServer.java line 38: put the file path to where the server should save the file received from the client.
- Edit TCPServer.java line 40: put the IP of the machine with ClientApp.java and TCPClient.java on it.
- Run TCPServerRouter.java first.
- Run TCPServer.java second.
- WAIT for server to write that it is connected to the router.
- Run TCPClient.java.
- Optional: Repeat steps 12-14 for other Server/Client pairs that are prepped to connect using the same Server Router.