using Astralis; using Invercargill; using Invercargill.DataStructures; public class RemoteAddressExample : Object { public static int main(string[] args) { // Create a simple handler that logs the client's remote address var handler = new SimpleHttpHandler(); // Start the server on port 8080 var server = new Server(8080, handler); server.run(); return 0; } } // Simple handler that responds with client information public class SimpleHttpHandler : Object, RequestHandler { public async HttpResult handle_request(HttpContext context) throws Error { var request = context.request; // Access the remote address var remote_address = request.remote_address; // Build JSON response with client info using string interpolation var json = @"{ \"method\": \"$(request.method)\", \"path\": \"$(request.raw_path)\", \"remote_address\": \"$(remote_address ?? "unknown")\", \"user_agent\": \"$(request.user_agent ?? "unknown")\" }"; var response = new HttpStringResult(json) .set_header("Content-Type", "application/json") .set_header("Access-Control-Allow-Origin", "*"); // Log the request to console print(@"[$(get_current_time())] $(request.method) $(request.raw_path) from $(remote_address ?? "unknown")\n"); return response; } private static string get_current_time() { var now = new DateTime.now_local(); return now.format("%Y-%m-%d %H:%M:%S"); } }