net Module
The net module offers network communication primitives: TCP clients and servers, UDP sockets, raw sockets, URL parsing, URLSearchParams, DNS resolution, and TLS client connections.
Importing
djazair
use net
TCP Client and Server
djazair
use net
# 1. High-Performance TCP Server (asynchronous Poller)
let server = new net.tcpServer(fn(client, ip, port)
print("New connection from ${ip}:${port}")
client.send("Welcome to Djazair TCP Server!
")
client.close()
end)
# Start listening on port 9000
server.listen(9000)
# 2. TCP Client
let client = new net.tcpClient()
client.connect("127.0.0.1", 9000)
client.send("Hello Server")
let reply = client.receive()
print("Received: " + reply)
client.close()
URL Parsing & Query Strings
djazair
use net
let u = net.parseURL("https://api.example.com:8080/v1/users?role=admin&active=true")
print("Host: ${u.hostname}") # => api.example.com
print("Port: ${u.port}") # => 8080
print("Path: ${u.pathname}") # => /v1/users
# Query Parameters
let params = u.searchParams
print("Role: ${params.get("role")}") # => admin
print("Active? ${params.has("active")}") # => True