This system consists of a server and multiple client processes. Each client process will connect to the server over a socket connection and register a user name at the server.
The server and the client are managed with a simple GUI. The messages exchanged between server and client use HTTP format.
Each client implements a simple four-function calculator to handle below operations:
- Addition
- Subtraction
- Multiplication
- Division
- Negative numbers
- Decimals to four digits, rounding up
The required actions are summarized as follows:
The client will execute the following sequence of steps:
- Initialize a local copy of the shared value.
- Connect to the server via a socket.
- Provide the server with a unique user name.
- Wait to be polled by server. While waiting:
- Allow users to input and execute operations on the four-function calculator.
- Log user-input in persistent storage.
- When polled by the server, upload all user-input (sequence of operations) logged since previous poll.
- Overwrite local copy of shared value with server copy.
- Notify user local copy has been updated.
- Repeat at step 4 until the process is killed by the user.
The server will execute the following sequence of steps:
- Initialize server copy of shared value.
- Startup and listen for incoming connections.
- Print that a client has connected and fork a thread to handle that client.
- When instructed by the user, poll clients for user-input sequence.
- Display received input sequences from clients on GUI.
- Apply user-input sequence to server copy of shared value.
- Push updated copy of shared value to clients.
- Begin at step 4 until server is closed by the user.
ServerGUI
extendsjavafx.application.Application
HTTPServer
extendsjava.lang.Thread
ServerThread
extendsjava.lang.Thread
ClientGUI
extendsjavafx.application.Application
Client
extendsjava.lang.Thread
javac HTTPServer.java
javac ServerGUI.java
javac ClientGUI.java
java ServerGUI
java ClientGUI
- JavaFX: Working with the JavaFX Scene Graph – https://docs.oracle.com/javase/8/javafx/scene-graph-tutorial/scenegraph.htm
- Interface
ObservableList<E>
– https://docs.oracle.com/javase/8/javafx/api/javafx/collections/ObservableList.html - Introducing Threads in Socket Programming in Java – https://www.geeksforgeeks.org/introducing-threads-socket-programming-java/
This code was submitted as part of Distributed Systems course assignment at The University of Texas at Arlington to Prof. Chance Eary (https://mentis.uta.edu/explore/profile/chance-eary)