{
"id": "269",
"prompt": "Give me a WebSocket status panel. host::net is the poll-model socket bridge and its ABI is INTEGER-ONLY: open(url_ptr) wants a pointer to a length-prefixed URL already in cartridge memory - a rustlite string literal will NOT type-check there (literals only flow into String-typed host params like http::get), so a refused open returning -1 is a state you must render. Latch one open(0) attempt behind an init slot, then map status(handle) 0/1/2/3 to CONNECTING / OPEN / CLOSING / CLOSED with a colored lamp, plus a distinct OFFLINE face when the handle is negative.",
"solution_rl": "fn frame(t: i32) {\n host::display::clear(0x0a0a12);\n if host::display::state_get(0) == 0 {\n host::display::state_set(1, host::net::open(\"wss://relay.example.net/lamp\"));\n host::display::state_set(0, 1);\n }\n let h: i32 = host::display::state_get(1);\n let mut s: i32 = -1;\n if h >= 0 {\n s = host::net::status(h);\n }\n let mut col: i32 = 0x555555;\n if s == 0 {\n col = 0xaa7700;\n } else if s == 1 {\n col = 0x22bb44;\n } else if s == 2 {\n col = 0xbb7722;\n } else if s == 3 {\n col = 0xbb2222;\n }\n host::display::draw_string(130, 60, \"SOCKET STATUS\", 0xffffff, 2);\n host::display::fill_rect(216, 140, 80, 80, col);\n if h < 0 {\n host::display::draw_string(190, 260, \"OFFLINE\", 0xbb2222, 2);\n host::display::draw_string(112, 300, \"OPEN REFUSED THE URL POINTER\", 0x777777, 1);\n } else if s == 0 {\n host::display::draw_string(160, 260, \"CONNECTING\", 0xaa7700, 2);\n } else if s == 1 {\n host::display::draw_string(208, 260, \"OPEN\", 0x22bb44, 2);\n } else if s == 2 {\n host::display::draw_string(184, 260, \"CLOSING\", 0xbb7722, 2);\n } else {\n host::display::draw_string(190, 260, \"CLOSED\", 0xbb2222, 2);\n }\n host::display::draw_string(200, 340, \"HANDLE\", 0x888888, 1);\n host::display::draw_number(248, 338, h, 0xffffff, 1);\n host::display::present();\n}\n",
"tags": [
"net",
"poll-model",
"status"
]
}