Arc Cross Reference

open-socket

[procedure] open-socket port

[procedure] socket-accept socket

Opens TCP server socket, and accepts connections to it.

open-socket returns a bound and listening socket, using MzScheme's scheme:tcp-listen.

(xdef 'open-socket  (lambda (num) (tcp-listen num 50 #t)))

socket-accept takes the listening socket, and blocks until a client connects to it. Returns list of three elements: an input port and an output port to talk to the client, and a string representation of the client's IP address.

(xdef 'socket-accept (lambda (s)
                       (call-with-values
                         (lambda () (tcp-accept s))
                         (lambda (in out)
                           (list (make-limited-input-port in 100000 #t)
                                 out
                                 (let-values (((us them) (tcp-addresses out)))
                                   them))))))

The socket created by open-socket can be closed by close.