\HeaderA{read.socket}{Read from or Write to a Socket}{read.socket}
\aliasA{write.socket}{read.socket}{write.socket}
\keyword{misc}{read.socket}
\begin{Description}\relax
\code{read.socket} reads a string from the specified socket,
\code{write.socket} writes to the specified socket.  There is very
little error checking done by either.
\end{Description}
\begin{Usage}
\begin{verbatim}
read.socket(socket, maxlen = 256, loop = FALSE)
write.socket(socket, string)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{socket}] a socket object
\item[\code{maxlen}] maximum length of string to read
\item[\code{loop}] wait for ever if there is nothing to read?
\item[\code{string}] string to write to socket
\end{ldescription}
\end{Arguments}
\begin{Value}
\code{read.socket} returns the string read.
\end{Value}
\begin{Author}\relax
Thomas Lumley
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{close.socket}{close.socket}}, \code{\LinkA{make.socket}{make.socket}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
finger <- function(user, host = "localhost", port = 79, print = TRUE)
{
    if (!is.character(user))
        stop("user name must be a string")
    user <- paste(user,"\r\n")
    socket <- make.socket(host, port)
    on.exit(close.socket(socket))
    write.socket(socket, user)
    output <- character(0)
    repeat{
        ss <- read.socket(socket)
        if (ss == "") break
        output <- paste(output, ss)
    }
    close.socket(socket)
    if (print) cat(output)
    invisible(output)
}
## Not run: 
finger("root")  ## only works if your site provides a finger daemon
## End(Not run)
\end{ExampleCode}
\end{Examples}

