A .NET 8 SimpleRPC-based distributed simulation of gas pressure in a container with three components:
- Server: container state and business logic (pressure, mass, temperature, safety limits)
- Input clients: add gas mass when pressure is below the lower limit
- Output clients: remove gas mass when pressure is above the upper limit
- Demonstrate contract-first remote interactions using SimpleRPC
- Keep contracts RPC-agnostic and separate from business logic
- Support many concurrent clients safely without races or deadlocks
- GasContract (class library)
IGasContainerServicedefines the remote service contract.
- gasPressure (server)
- Implements the service and hosts SimpleRPC.
- Every ~2 seconds updates temperature with a random delta and recomputes pressure.
- Resets simulation on implosion/explosion.
- inputClient (client)
- If pressure < lower limit, generates positive random mass and calls
AddMass.
- If pressure < lower limit, generates positive random mass and calls
- outputClient (client)
- If pressure > upper limit, generates positive random mass and calls
RemoveMass.
- If pressure > upper limit, generates positive random mass and calls
- Clients obtain a proxy for
IGasContainerServiceusing SimpleRPC and the shared GasContract DLL. - Clients call short, non-blocking methods (get state, add mass, remove mass).
- Server validates constraints and applies updates atomically, logs each step.
- Server’s timer adjusts temperature; clients react next cycle.
- One server, unlimited clients: yes
- Interfaces for contracts:
IGasContainerService - Contract/logic separation: contract lib vs. server/clients
- No sleeping in service ops: yes (timer runs outside RPC calls)
- Proxy-based RPC: SimpleRPC proxies
- No races/deadlocks: serialized updates in server, short calls
- Continuous cycles: server timer + client loops
- Separate processes: server and each client run separately
- Logging: to stdout/files
Prerequisites: .NET SDK 8+
Build all
dotnet buildRun server (terminal 1)
dotnet run --project gasPressureRun one or more input clients (terminal 2+)
dotnet run --project inputClientRun one or more output clients (terminal 3+)
dotnet run --project outputClientConfiguration such as limits/endpoints/logging is in gasPressure/appsettings.json (and Development override).
Default: MIT (see LICENSE).