Overview
The server implementation (backend/server.py) contains the actual conversion logic and servant class that handles remote requests from ICE clients.
Servant Class
The servant class inherits from the generated base class and implements all interface methods:Conversor.ConversorUnidades is the base class generated by slice2py from the .ice file. Your servant must inherit from this class.Conversion Algorithms
All conversion methods follow a common pattern: convert to a base unit first, then convert from the base unit to the target unit.Temperature Conversion
Base unit: Celsiusbackend/server.py
- Fahrenheit to Celsius:
(F - 32) × 5/9 - Kelvin to Celsius:
K - 273.15 - Celsius to Fahrenheit:
C × 9/5 + 32 - Celsius to Kelvin:
C + 273.15
Length Conversion
Base unit: Meters (m)backend/server.py
- 1 meter = 1.0 m
- 1 kilometer = 1000.0 m
- 1 mile = 1609.344 m
- 1 foot = 0.3048 m
Weight Conversion
Base unit: Kilograms (kg)backend/server.py
- 1 kilogram = 1.0 kg
- 1 pound = 0.453592 kg
- 1 gram = 0.001 kg
Velocity Conversion
Base unit: Meters per second (m/s)backend/server.py
- 1 m/s = 1.0 m/s
- 1 km/h = 1/3.6 m/s (approximately 0.277778 m/s)
- 1 mph = 0.44704 m/s
Available Units Query
backend/server.py
Validation and Error Handling
The private_validar method ensures that units are valid before attempting conversion:
backend/server.py
Server Initialization
Themain() function sets up and starts the ICE server:
Initialize the ICE runtime
--Ice.Trace.Network=2 for debugging.Create and register the servant
"ConversorUnidades" is the object identity that clients will use to locate this servant.Complete Server Code
Running the Server
Key Architecture Concepts
Servant
The server-side object that implements the interface methods defined in the
.ice file.Object Adapter
The component that receives incoming requests and routes them to the correct servant based on object identity.
Object Identity
A unique name (“ConversorUnidades”) that clients use to locate the servant within the adapter.
Endpoint
The network address and port where the server listens for connections (TCP port 10000).
Debugging Tips
Next Steps
Client Usage
Learn how to connect to the server and make remote calls