The R Project SVN R

Rev

Rev 42333 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
27442 ripley 1
\name{read.socket}
2
\title{ Read from or Write to a Socket}
3
\usage{
4
read.socket(socket, maxlen=256, loop=FALSE)
5
write.socket(socket, string)
6
}
7
\alias{read.socket}
8
\alias{write.socket}
9
\arguments{
10
    \item{socket}{a socket object}
11
    \item{maxlen}{maximum length of string to read}
12
    \item{loop}{wait for ever if there is nothing to read?}
13
    \item{string}{string to write to socket}
14
}
15
\description{
16
    \code{read.socket} reads a string from the specified socket,
17
    \code{write.socket} writes to the specified socket.  There is very
18
    little error checking done by either.
19
}
20
\value{
21
    \code{read.socket} returns the string read.
22
}
23
\author{Thomas Lumley}
24
 
25
\seealso{
26
    \code{\link{close.socket}}, \code{\link{make.socket}}
27
}
28
 
29
\examples{
30
finger <- function(user, host = "localhost", port = 79, print = TRUE)
31
{
32
    if (!is.character(user))
33
        stop("user name must be a string")
34
    user <- paste(user,"\r\n")
35
    socket <- make.socket(host, port)
36
    on.exit(close.socket(socket))
37
    write.socket(socket, user)
38
    output <- character(0)
39
    repeat{
40
        ss <- read.socket(socket)
41
        if (ss == "") break
42
        output <- paste(output, ss)
43
    }
44
    close.socket(socket)
45
    if (print) cat(output)
46
    invisible(output)
47
}
48
\dontrun{finger("root")  ## only works if your site provides a finger daemon}
49
}
50
\keyword{misc}