\Header{make.socket}{Create a socket connection}
\keyword{misc}{make.socket}
\begin{Usage}
\begin{verbatim}
make.socket(host="localhost", port, fail=TRUE, server=FALSE)
close.socket(socket)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\texttt{host}] name of remote host
\item[\texttt{port}] port to connect to/listen on
\item[\texttt{fail}] failure to connect is an error?
\item[\texttt{server}] a server socket?
\end{ldescription}
\end{Arguments}
\begin{Description}
With \texttt{server=FALSE} attempts to open a client socket to the
specified port and host. With \texttt{server=TRUE} listens on the
specified port for a connection and then returns a server socket. It is
a good idea to use \texttt{\Link{on.exit}} to ensure that a socket is
closed, as you only get 64 of them.\end{Description}
\begin{Value}
An object of class \texttt{"socket"}.
\begin{ldescription}
\item[\texttt{socket}] socket number. This is for internal use
\item[\texttt{port}] port number of the connection
\item[\texttt{host}] name of remote computer
\end{ldescription}
\end{Value}
\begin{Section}{WARNING}
I don't know if the connecting host name returned
when \texttt{server=TRUE} can be trusted. I suspect not.\end{Section}
\begin{Author}
Thomas Lumley\end{Author}
\begin{References}
Adapted from Luke Tierney's code for \texttt{XLISP-Stat}, in turn
based on code from Robbins and Robbins "Practical UNIX Programming"\end{References}
\begin{SeeAlso}
\texttt{\Link{close.socket}}, \texttt{\Link{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)
}
daytime()  ## only works if your computer runs this service
daytime("chime.cac.washington.edu")
\end{ExampleCode}
\end{Examples}

