\HeaderA{make.socket}{Create a Socket Connection}{make.socket}
\aliasA{print.socket}{make.socket}{print.socket}
\keyword{misc}{make.socket}
\begin{Description}\relax
With \code{server = FALSE} attempts to open a client socket to the
specified port and host. With \code{server = TRUE} listens on the
specified port for a connection and then returns a server socket. It is
a good idea to use \code{\LinkA{on.exit}{on.exit}} to ensure that a socket is
closed, as you only get 64 of them.
\end{Description}
\begin{Usage}
\begin{verbatim}
make.socket(host = "localhost", port, fail = TRUE, server = FALSE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{host}] name of remote host
\item[\code{port}] port to connect to/listen on
\item[\code{fail}] failure to connect is an error?
\item[\code{server}] a server socket?
\end{ldescription}
\end{Arguments}
\begin{Value}
An object of class \code{"socket"}.
\begin{ldescription}
\item[\code{socket}] socket number. This is for internal use
\item[\code{port}] port number of the connection
\item[\code{host}] name of remote computer
\end{ldescription}
\end{Value}
\begin{Section}{Warning}
I don't know if the connecting host name returned
when \code{server = TRUE} can be trusted. I suspect not.
\end{Section}
\begin{Author}\relax
Thomas Lumley
\end{Author}
\begin{References}\relax
Adapted from Luke Tierney's code for \code{XLISP-Stat}, in turn
based on code from Robbins and Robbins "Practical UNIX Programming"
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{close.socket}{close.socket}}, \code{\LinkA{read.socket}{read.socket}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
daytime <- function(host = "localhost"){
    a <- make.socket(host, 13)
    on.exit(close.socket(a))
    read.socket(a)
}
## Offical time (UTC) from US Naval Observatory
## Not run: daytime("tick.usno.navy.mil")
\end{ExampleCode}
\end{Examples}

