The SockUtil structure provides a collection of utility functions for
programming with the Basis Library
Socket structure
Synopsis
signature SOCK_UTIL
structure SockUtil : SOCK_UTIL
Interface
datatype port = PortNumber of int | ServName of string
datatype hostname = HostName of string | HostAddr of NetHostDB.in_addr
val scanAddr : (char, 'a) StringCvt.reader
-> ({host : hostname, port : port option}, 'a) StringCvt.reader
val addrFromString : string -> {host : hostname, port : port option} option
exception BadAddr of string
val resolveAddr : {host : hostname, port : port option}
-> {host : string, addr : NetHostDB.in_addr, port : int option}
type 'a stream_sock = ('a, Socket.active Socket.stream) Socket.sock
val connectINetStrm : {addr : NetHostDB.in_addr, port : int}
-> INetSock.inet stream_sock
val recvVec : ('a stream_sock * int) -> Word8Vector.vector
val recvStr : ('a stream_sock * int) -> string
val sendVec : ('a stream_sock * Word8Vector.vector) -> unit
val sendStr : ('a stream_sock * string) -> unit
val sendArr : ('a stream_sock * Word8Array.array) -> unit
Description
datatype port = PortNumber of int | ServName of string-
specifies a port identifier, which either be a number (
Port) or the name of a service (ServName). datatype hostname = HostName of string | HostAddr of NetHostDB.in_addr-
something
val scanAddr : (char, 'a) StringCvt.reader -> ({host : hostname, port : port option}, 'a) StringCvt.reader-
scanAddr getcreturns an address reader. An address is a string of the form \(\mathit{addr}\,[\,\mathtt{:}\,\mathit{port}\,\)], where \(\mathit{addr}\) may either be a numeric or symbolic host name and the optional port is either a decimal port number or alphanumeric service name. Legal host names must begin with a letter, and may contain any alphanumeric character, the minus sign (-) and period (.), where the period is used as a domain separator. val addrFromString : string -> {host : hostname, port : port option} option-
addrFromString addrconverts the stringaddrto a host-port address specifier. The syntax of addresses is as described forscanAddr.
exception BadAddr of string-
This exception is raised by
resolveAddr.
val resolveAddr : {host : hostname, port : port option} -> {host : string, addr : NetHostDB.in_addr, port : int option}-
resolveAddr {host, port}resolves the hostname and optional port in the host and service databases. If either the host or service name is not found, then theBadAddrexception is raised. type 'a stream_sock = ('a, Socket.active Socket.stream) Socket.sock-
A type abbreviation for active stream sockets.
val connectINetStrm : {addr : NetHostDB.in_addr, port : int} -> INetSock.inet stream_sock-
connectINetStrm {addr, port}establishs a client-side connection to an INET domain stream socket. val recvVec : ('a stream_sock * int) -> Word8Vector.vector-
recvVec (sock, n)readsnbytes from the stream socketsock; fewer thannbytes is returned when the stream is closed at the other end of the connection. It raises theSizeexception whennis negative. val recvStr : ('a stream_sock * int) -> string-
recvStr (sock, n)readsncharacters from the stream socketsock; fewer thanncharacters is returned when the stream is closed at the other end of the connection. It raises theSizeexception whennis negative. val sendVec : ('a stream_sock * Word8Vector.vector) -> unit-
sendVec (sock, vec)sends the vectorvecon the stream socketsock. val sendStr : ('a stream_sock * string) -> unit-
sendStr (sock, s)sends the stringson the stream socketsock. val sendArr : ('a stream_sock * Word8Array.array) -> unit-
sendArr (sock, arr)sends the arrayarron the stream socketsock.