Files
wren/example/websocket_chat_client.wren
T
retoor fdd61cc90c feat: add cJSON and SQLite amalgamation source files under deps/
Add the cJSON library (cJSON.c, cJSON.h) and SQLite amalgamation
(sqlite3.c, sqlite3.h, sqlite3ext.h, shell.c) as vendored dependencies
in the deps/ directory for use by the project build system.
2026-01-24 18:35:43 +00:00

50 lines
985 B
JavaScript
Vendored

// retoor <retoor@molodetz.nl>
import "websocket" for WebSocket
import "scheduler" for Scheduler
import "timer" for Timer
import "io" for Stdin
var host = "ws://127.0.0.1:8080"
System.print("=== WebSocket Chat Client ===")
System.print("Connecting to %(host)...")
var ws = WebSocket.connect(host)
System.print("Connected!")
System.print("Commands: /name <name>, /who, /quit")
System.print("Type a message and press Enter to send.\n")
var running = true
Scheduler.add {
while (running && ws.isOpen) {
var msg = ws.receive()
if (msg == null || msg.isClose) {
running = false
System.print("\nConnection closed.")
break
}
if (msg.isText) {
System.print(msg.text)
}
}
}
Timer.sleep(100)
while (running && ws.isOpen) {
System.write("> ")
var line = Stdin.readLine()
if (line == null || line == "/quit") {
running = false
break
}
if (line.count > 0) {
ws.send(line)
}
}
ws.close()
System.print("Disconnected.")