-
Notifications
You must be signed in to change notification settings - Fork 2
tcp socket
TurtleKitty edited this page May 11, 2019
·
3 revisions
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.
(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
(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