game/src/net/link.rs#
Source: lib/game/src/net/link.rs
link -- the netcode on real sockets: netchan's Server and Client under NetServer and NetClient
serve(server, game, now_ns) one round of a server's loop: netchan's events into the game, the ticks
due, the game's messages out, the connections it ends closed (Windows,
Linux, Apple: netchan::Server needs netio)
NetLink<M> a client's channel and, when WELCOME asks for it, the fetch's WebSocket
(ws://host:port/path of the server's UDP address); pump(map, now) reads
both, flush() sends what the game queued, leave() ends it cleanly (LEAVE,
then netchan's DISCONNECT: the server removes the figure at once)
A server's loop: serve(..) then server.wait(ms to the next tick) (never plat::sleep_ms(1) on Windows:
docs/TRANSPORT.md). A client's frame: link.pump(map, now), n = link.game.advance(now), n times
link.game.step(map, input), link.flush().
fn serve<S: super::server::RoomSim>(server: &mut netchan::Server, game: &mut super::server::NetServer<S>, now_ns: u64) -> u32one round of a server's loop (see the module header) -> the ticks runstruct NetLink<M: Movement>a client's channels (see the module header)game: NetClient<M>-- the game's clientsend_errors: u64-- sends netchan refused (Size, Backlog, NotConnected)
impl<M: Movement> NetLink<M>
fn connect(ep: Endpoint, cfg: ClientConfig, game: NetClient<M>, path: &str) -> Result<NetLink<M>, netchan::Error>connect toep;pathis the server's WebSocket path (for a fetch of a UDP client)fn pump(&mut self, map: &physics::World, now_ns: u64)read the channels, feed the game, open the fetch when askedfn flush(&mut self)send what the game queuedfn leave(&mut self)leave the room: LEAVE (the server removes the figure at once), then netchan's DISCONNECT (over UDP three times) and the end of a fetch's WebSocket. Dropping a NetLink only does the last twofn channel(&self) -> &Clientthe main channel (its state, stats, round-trip time)fn fetching(&self) -> boola fetch's WebSocket is open