moonnet — the networking front door for MoonBit: one import that re-exports moonhttp, moontls and moonquic, and the connection layer that ties those formats to sockets.
// A TLS server: the handshake is done before the handler sees the connection.
let tls = @tls.Server::new(@x509.pems(cert_pem), @x509.PrivateKey::pem(key_pem), alpn=["h2", "http/1.1"])
@tcp.serve(tls~, (conn, peer) => {
while conn.read_until("\n") is Some(line) {
conn.write(line + "\n")
}
})
// A client: resolved, connected, the chain judged against the roots.
let conn = @tcp.dial("example.com", port=443, tls=@tls.Client::new(@roots.mozilla(), alpn=["http/1.1"]))
conn.write("GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")| Package | What it does | State |
|---|---|---|
| tcp | TCP and TLS over TCP: a connection that reads and writes the same either way, the accept loop, the dialler, and a sniff that tells an HTTP/2 preface from an HTTP/1.1 request without consuming it | 0.1.0 |
| Conn::plain(sock) | A socket in the clear |
| Conn::server(sock, config) | The server side of TLS, returned after the handshake |
| Conn::client(sock, config, host) | The client side, returned after the server's chain is judged |
| starts_with(prefix) | Whether the stream opens with prefix; reads only as far as the first byte that differs |
| alpn(), server_name(), peer() | What the handshake settled; None and empty in the clear |
| shutdown(), close() | close_notify, then the socket |
moon add moonbitstack/moonnetInstall
Download zipmoonnet — the networking front door for MoonBit: one import that re-exports moonhttp, moontls and moonquic, and the connection layer that ties those formats to sockets.