JFLib

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) -> u32 one round of a server's loop (see the module header) -> the ticks run

impl<M: Movement> NetLink<M>

  • fn connect(ep: Endpoint, cfg: ClientConfig, game: NetClient<M>, path: &str) -> Result<NetLink<M>, netchan::Error> connect to ep; path is 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 asked
  • fn flush(&mut self) send what the game queued
  • fn 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 two
  • fn channel(&self) -> &Client the main channel (its state, stats, round-trip time)
  • fn fetching(&self) -> bool a fetch's WebSocket is open

Source: docs/API.md in the JFLib repository.