Port → Port Settings

Port Settings

Each port maintains its own TokenBucket per player, completely independent from the main App channel and from other ports. Pass a settings table as the third argument to app:Listen().

Settings reference

OptionTypeDefaultDescription
maxTokensnumber60Token bucket max capacity per player
refillRatenumber20Tokens added per second per player
startTokensnumbermaxTokensInitial token count when a player joins
costnumber1Tokens consumed per request on this port

Example

-- A high-frequency combat port: tight limits
app:Listen("combat", function(port)
    port:Post("shoot/:targetId=number", function(req, res)
        res:Send(handleShoot(req.player, req.params.targetId))
    end)
end, {
    maxTokens  = 20,
    refillRate = 10,
    startTokens = 10,
    cost       = 1,
})

-- A low-frequency inventory port: generous limits
app:Listen("inventory", function(port)
    port:Get("items", function(req, res)
        res:Send(getInventory(req.player))
    end)
end, {
    maxTokens  = 60,
    refillRate = 20,
})

Independence guarantee

Each port's TokenBucket is fully independent. A burst of combat requests that drains a player's combat tokens has no effect on their inventory token count. This is the core isolation guarantee of ports.

Omitting settings. If you omit the settings table entirely, the port uses the defaults shown above (60 max tokens, 20/s refill). This is suitable for moderate-frequency channels. High-frequency ports like combat should use lower values to prevent abuse.

See also

← Port  ·  Creating Ports | full Listen signature  ·  Using Ports | client-side access  ·  TokenBucket | token bucket internals