DCS World Typescript
    Preparing search index...

    An HTTP/1.1 server driven cooperatively from a host loop or timer callback.

    Every socket is non-blocking. Each call to pump accepts a bounded number of new connections and then visits the open connections round-robin, starting where the previous pump stopped. A visit does whatever progress is possible without waiting: it reads available request bytes, runs the request handler once the request is complete, and writes as much of the response as the socket accepts. A connection that cannot make progress keeps its state and is revisited on a later pump, so an idle or slow client never holds up the others.

    Each connection serves one request and is closed once the whole response has been handed to the socket. Every response carries Connection: close. Keep-alive, pipelining and chunked request bodies are not supported; see the package README for the request forms that are rejected, and HttpServerOptions for the limits, deadlines and per-pump budgets.

    The request handler is synchronous and runs to completion inside a pump; the pump's time budget cannot interrupt it, but no new handler starts once the budget is spent.

    // Serve 200 for every request, pumping from a DCS timer (use a wall clock, not simulation time).
    const httpServer = new HttpServer("127.0.0.1", 8080, (req, res) => { res.status = 200; return res; });
    timer.scheduleFunction((_, time) => { httpServer.pump(); return time + 0.02; }, undefined, timer.getTime() + 0.02);

    Hierarchy (View Summary)

    Index

    The request handler to be used when serving requests

    logger: Logger
    server: TCP

    The underlying TCP server.

    • Legacy entry point, kept for compatibility: it runs one pump.

      Unlike earlier versions it neither handles exactly one client nor finishes a request within the call: a call may accept several clients and advance several connections, and a request may take several calls to be read and answered. Keep calling it repeatedly, as before.

      Returns void

      Use pump.

    • Closes the listening socket and every open connection and releases their buffers. Safe to call more than once; later calls, and later pumps, do nothing.

      Returns void

    • The number of open connections. (A method rather than a getter: accessors would slow every property access on the server and its subclasses in the generated Lua.)

      Returns number

    • Does a bounded amount of work and returns: accepts up to maxAcceptsPerPump new connections (while fewer than maxConnections are open), then visits open connections round-robin within the per-pump budgets. Call it repeatedly, for example from a timer callback; it never waits for a socket.

      Returns PumpStats

      What this pump did. Cheap to ignore; useful for instrumentation.