Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
exchange.Go
EventLoop
ctx.subscribe
ctx.poll
ctx.order
ctx.cancel
ctx.orderAsync
ctx.cancelAsync
Subscription
threading
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Server
Server.addr
Server.close
Server.stop
Server.join
Server.pending
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Returns the address and port the service actually listens on.

addr()

Examples

Start an HTTP service on a random port, watch the pending requests, then shut it down gracefully.

javascript
function main() { // Port 0 picks a free port; addr() returns the actual address var server = threading.Serve("http://127.0.0.1:0", function (ctx) { Sleep(1000) ctx.write("done") }) Log("listen on", server.addr()) // Output: listen on 127.0.0.1:<random port> // Send a request from another thread while the main thread watches the server threading.Thread(function (addr) { Log("response:", HttpQuery("http://" + addr + "/")) // Output: response: done (about 1 second later) }, server.addr()) Sleep(200) Log("pending:", server.pending()) // Output: pending: 1 (one request is being handled) // Stop accepting connections; requests in flight run to completion server.close() Log("idle:", server.join(5000)) // Output: idle: true (the server is closed and every request has finished) }

Returns

TypeDescription

string

The listening address, such as 127.0.0.1:8088 or 0.0.0.0:8089; with port 0 it contains the port the system picked.

See Also