Skip to content

About

Java simulation of the token ring algorithm for distributed mutual exclusion: a token passes between UDP clients and only its holder may send to the server.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Token Ring Mutual Exclusion Algorithm Simulation

A Java simulation of the token ring algorithm for distributed mutual exclusion. A token passes between clients over UDP, and only the client that holds the token may send data to the server.

How it works

  • Server/TokenServer.java listens on UDP port 8000 and prints every message it receives.
  • Client/Client.java runs a client. When it holds the token it asks whether you want to enter data, sends it to the server, then passes the token on.
  • Client/TokenClient.java and Server/Server.java hold the UDP send and receive logic.

The report (Ahmed217380-Assignment1.docx) and the screenshots in this repository show a sample run.

Requirements

JDK 17 and Maven 3.9.

Build and run

cd Token-Ring_Mutual_Exclusion_Algorithm_Simulation
mvn compile

# terminal 1: the server
java -Dfile.encoding=UTF-8 -cp target/classes Server.TokenServer

# terminal 2: a client
java -Dfile.encoding=UTF-8 -cp target/classes Client.Client

In the client, answer yes to send a line of text to the server, or no to pass the token on. After no the client waits for the token to come back on UDP port 8002. To try it by hand, send the text Token to that port from another program. The generated TokenRing_Mutual_Exclusion_Algorithm_Simulation class only prints "Hello World!" and is not the entry point.

Checked with the server and one client: a line typed after yes arrived at the server, and after no the client received the Token and went back to the prompt.

What changed

  • The client created a new input reader for every question, which lost typed text and sent "null" to the server. It now uses one shared reader.
  • The packet length was counted in characters instead of bytes, so text with non-ASCII characters was cut off. It now uses the byte length and UTF-8.
  • Closing the input crashed the client with a NullPointerException. It now stops cleanly.

License

MIT. See LICENSE.

About

Java simulation of the token ring algorithm for distributed mutual exclusion: a token passes between UDP clients and only its holder may send to the server.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages