ludic/ns-udp.html
2026-09-17 22:10:03 +00:00

24 lines
No EOL
4 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Udp — Ludic</title>
<meta name="description" content="Plain IPv4 datagrams, polled — the transport under a game&#x27;s own netcode: peer-to-peer play, a LAN lobby, a STUN query.">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <span class="here">Udp</span></div>
<div class="item-head"><span class="kind-badge kind-namespace">namespace</span><h1 id="top">Udp</h1></div>
<p class="ns-blurb">Plain IPv4 datagrams, polled — the transport under a game's own netcode: peer-to-peer play, a LAN lobby, a STUN query. Open a socket with <a href="udp-open.html"><code>Udp.open</code></a>, send with <a href="udp-send.html"><code>Udp.send</code></a>, and each frame drain what arrived with <a href="udp-recv.html"><code>Udp.recv</code></a>, which returns <code>0</code> when nothing is waiting and never blocks. The sender of the last datagram read is <a href="udp-from_ip.html"><code>Udp.from_ip</code></a> / <a href="udp-from_port.html"><code>from_port</code></a>.
An address is an <code>int</code>: <code>a.b.c.d</code> is <code>(a &lt;&lt; 24) | (b &lt;&lt; 16) | (c &lt;&lt; 8) | d</code>, converted by <a href="udp-ip.html"><code>Udp.ip</code></a> and <a href="udp-ip_text.html"><code>Udp.ip_text</code></a>. Datagrams can be lost, repeated and reordered; the protocol a game builds on top says what to do about that. Like <code>Http.*</code> it is <strong>out-of-band</strong> and must never feed the deterministic lockstep/replay simulation directly. BSD sockets on macOS, Winsock on Windows.</p>
<div class="ns-methods"><a class="ns-method" href="udp-open.html"><code class="nm-sig">Udp.open(port) -&gt; int</code><span class="nm-tip">Open a socket on a port.</span></a><a class="ns-method" href="udp-port.html"><code class="nm-sig">Udp.port(socket) -&gt; int</code><span class="nm-tip">The port a socket is bound to.</span></a><a class="ns-method" href="udp-send.html"><code class="nm-sig">Udp.send(socket, ip, port, bytes, len) -&gt; int</code><span class="nm-tip">Send one datagram.</span></a><a class="ns-method" href="udp-recv.html"><code class="nm-sig">Udp.recv(socket, bytes, cap) -&gt; int</code><span class="nm-tip">Read the next waiting datagram.</span></a><a class="ns-method" href="udp-from_ip.html"><code class="nm-sig">Udp.from_ip(socket) -&gt; int</code><span class="nm-tip">The sender of the last datagram read.</span></a><a class="ns-method" href="udp-from_port.html"><code class="nm-sig">Udp.from_port(socket) -&gt; int</code><span class="nm-tip">The sender's port.</span></a><a class="ns-method" href="udp-close.html"><code class="nm-sig">Udp.close(socket) -&gt; void</code><span class="nm-tip">Close a socket.</span></a><a class="ns-method" href="udp-resolve.html"><code class="nm-sig">Udp.resolve(name) -&gt; int</code><span class="nm-tip">Look a host name up.</span></a><a class="ns-method" href="udp-local_ip.html"><code class="nm-sig">Udp.local_ip() -&gt; int</code><span class="nm-tip">This machine's address.</span></a><a class="ns-method" href="udp-ip.html"><code class="nm-sig">Udp.ip(text) -&gt; int</code><span class="nm-tip">Parse a dotted address.</span></a><a class="ns-method" href="udp-ip_text.html"><code class="nm-sig">Udp.ip_text(ip) -&gt; string</code><span class="nm-tip">Format an address.</span></a></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>