feat: add fswatch, sysinfo, and udp demo scripts plus reorder manual sidebar links
Add three new example scripts demonstrating the fswatch, sysinfo, and udp modules with file watching, system metrics, and UDP echo server/client patterns. Reorder the manual API sidebar navigation to list modules alphabetically, removing deprecated entries like websocket, tls, net, json, regex, jinja, os, signal, subprocess, sqlite, and timer while adding argparse, dataset, fswatch, and html.
This commit is contained in:
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "udp" for UdpSocket, UdpMessage
|
||||
import "timer" for Timer
|
||||
import "scheduler" for Scheduler
|
||||
|
||||
System.print("=== UDP Module Demo ===\n")
|
||||
|
||||
System.print("--- Basic UDP Echo Server ---")
|
||||
|
||||
var server = UdpSocket.new()
|
||||
server.bind("127.0.0.1", 8888)
|
||||
System.print("Server listening on %(server.localAddress):%(server.localPort)")
|
||||
|
||||
var client = UdpSocket.new()
|
||||
client.bind("127.0.0.1", 0)
|
||||
System.print("Client bound to %(client.localAddress):%(client.localPort)")
|
||||
|
||||
var messageCount = 0
|
||||
var maxMessages = 3
|
||||
|
||||
Scheduler.add {
|
||||
while (messageCount < maxMessages) {
|
||||
var msg = server.receive()
|
||||
if (msg == null) break
|
||||
|
||||
System.print("Server received: '%(msg[0])' from %(msg[1]):%(msg[2])")
|
||||
|
||||
server.send("Echo: %(msg[0])", msg[1], msg[2])
|
||||
messageCount = messageCount + 1
|
||||
}
|
||||
server.close()
|
||||
System.print("Server closed")
|
||||
}
|
||||
|
||||
Scheduler.add {
|
||||
var messages = ["Hello", "UDP", "World"]
|
||||
for (m in messages) {
|
||||
client.send(m, "127.0.0.1", 8888)
|
||||
System.print("Client sent: '%(m)'")
|
||||
|
||||
var response = client.receive()
|
||||
if (response != null) {
|
||||
System.print("Client received: '%(response[0])'")
|
||||
}
|
||||
}
|
||||
client.close()
|
||||
System.print("Client closed")
|
||||
}
|
||||
|
||||
Timer.sleep(500)
|
||||
|
||||
System.print("\n--- Broadcast Configuration ---")
|
||||
var bcast = UdpSocket.new()
|
||||
bcast.bind("0.0.0.0", 0)
|
||||
bcast.setBroadcast(true)
|
||||
System.print("Broadcast enabled on port %(bcast.localPort)")
|
||||
bcast.close()
|
||||
|
||||
System.print("\nDemo complete!")
|
||||
Reference in New Issue
Block a user