feat: add networking module with TCP Socket/Server and example applications
Implement a full-featured `net` module supporting TCP `Socket` and `Server` classes via libuv, including example applications (chat server, echo server, HTTP client/server, file explorer, system dashboard) and benchmark scripts (fibonacci, n-body). Add GEMINI.md project documentation and Stderr class to io module.
This commit is contained in:
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
import "net" for Socket
|
||||
import "scheduler" for Scheduler
|
||||
|
||||
class HttpClient {
|
||||
static get(host, port, path) {
|
||||
System.print("Connecting to %(host):%(port)...")
|
||||
var socket = Socket.connect(host, port)
|
||||
|
||||
var request = "GET %(path) HTTP/1.1\r\n" +
|
||||
"Host: %(host)\r\n" +
|
||||
"User-Agent: Wren-CLI\r\n" +
|
||||
"Connection: close\r\n" +
|
||||
"\r\n"
|
||||
|
||||
System.print("Sending request...")
|
||||
socket.write(request)
|
||||
|
||||
System.print("Waiting for response...")
|
||||
var response = ""
|
||||
while (true) {
|
||||
var chunk = socket.read()
|
||||
if (chunk == null) break
|
||||
response = response + chunk
|
||||
}
|
||||
|
||||
socket.close()
|
||||
return response
|
||||
}
|
||||
}
|
||||
|
||||
// Example usage: Fetching from a local server or a known public IP
|
||||
// Note: This implementation is for raw IP/DNS if supported by uv_tcp_connect.
|
||||
// Since our net.c uses uv_ip4_addr, we use localhost for the example.
|
||||
var host = "127.0.0.1"
|
||||
var port = 8080 // Try to connect to our own http_server example
|
||||
var path = "/"
|
||||
|
||||
var result = HttpClient.get(host, port, path)
|
||||
System.print("\n--- Response Received ---
|
||||
")
|
||||
System.print(result)
|
||||
Reference in New Issue
Block a user