TcpListener

accept

defn

(Fn [(Ref TcpListener a)] (Result TcpStream String))

                        (accept listener)
                    

accepts a new TCP connection, returning a TcpStream. Blocks until a client connects. Returns (Result TcpStream String).

bind

defn

(Fn [(Ref String a), Int] (Result TcpListener String))

                        (bind addr port)
                    

binds a TCP listener to the given address and port. The socket is set to reuse address/port and starts listening immediately. Returns (Result TcpListener String).

close

external

(Fn [TcpListener] ())

closes the listener, releasing the file descriptor.

copy

external

(Fn [(Ref TcpListener a)] TcpListener)

local-address

external

(Fn [(Ref TcpListener a)] String)

returns the IP address the listener is bound to.

local-port

external

(Fn [(Ref TcpListener a)] Int)

returns the port the listener is bound to. Useful when binding to port 0 (OS-assigned).

poll-fd

defn

(Fn [(Ref TcpListener a)] Int)

                        (poll-fd l)
                    

set-reuseaddr

external

(Fn [(Ref TcpListener a), Int] ())

enables or disables SO_REUSEADDR on the listener.

while-accept

macro

Macro

                        (while-accept listener name :rest forms)
                    

accepts connections in a loop. Binds each accepted stream to name and executes forms, then closes the stream. Loops forever.