Skip to content

tcp socket

TurtleKitty edited this page May 11, 2019 · 3 revisions

TCP socket

A tcp-socket is a special port that can speak to the network. It is bidirectional, so supports the methods of both sink and source streams.

Sockets come from two places: sys.tcp.connect or the accept method of a tcp-listener created by sys.tcp.listen.

listener messages

(def server (sys.tcp.listen "127.0.0.1" 64764))

server.type    ; (tcp listener)
server.port    ; 64764
server.accept  ; returns (tcp socket source sink stream)
server.close   ; this kills the server

socket messages

(def client (sys.tcp.connect "127.0.0.1" 64764))

client.type          ; (tcp socket source sink stream)
client.local-addr    ; <local IP address of the socket>
client.local-port    ; <local port number of the socket>
client.remote-addr   ; "127.0.0.1"
client.remote-port   ; 64764
client.close         ; this kills the socket
Clone this wiki locally