Next: Common-Lisp-style formatting, Previous: I/O extensions, Up: Libraries
Scheme48 provides a simple facility for TCP & UDP sockets. Both the
structures sockets
and udp-sockets
export several general
socket-related procedures:
Close-socket
closes socket, which may be any type of socket.Socket-port-number
returns the port number through which socket is communicating.Get-host-name
returns the network name of the current machine.Note: Programmers should be wary of storing the result of a call to
get-host-name
in a dumped heap image, because the actual machine's host name may vary from invocation to invocation of the Scheme48 VM on that image, since heap images may be resumed on multiple different machines.
The sockets
structure provides simple TCP socket facilities.
The server interface.
Open-socket
creates a socket that listens on port-number, which defaults to a random number above 1024.Socket-accept
blocks until there is a client waiting to be accepted, at which point it returns two values: an input port & an output port to send & receive data to & from the client.
Connects to the server at port-number denoted by the machine name host-name and returns an input port and an output port for sending & receiving data to & from the server.
Socket-client
blocks the current thread until the server accepts the connection request.
The udp-sockets
structure defines a UDP socket facility.
Opens a UDP socket on port-number, or a random port number if none was passed.
Open-udp-socket
returns two values: an input UDP socket and an output UDP socket.
Udp-send
attempts to send count elements from the string or byte vector buffer from the output UDP socket socket to the UDP address address, and returns the number of octets it successfully sent.Udp-receive
receives a UDP message from socket, reading it into buffer destructively. It returns two values: the number of octets read into buffer and the address whence the octets came.
Lookup-udp-address
returns a UDP address for the machine name name at the port number port.Udp-address?
is the disjoint type predicate for UDP addresses.Udp-address-address
returns a byte vector that contains the C representation of address, suitable for passing to C with Scheme48's C FFI.Udp-address-port
returns the port number of address.Udp-address-hostname
returns a string representation of the IP address of address.