The R Project SVN R

Rev

Rev 61433 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/utils/man/read.socket.Rd
68948 ripley 2
% Part of the R package, https://www.R-project.org
60528 ripley 3
% Copyright 1995-2012 R Core Team
42333 ripley 4
% Distributed under GPL 2 or later
5
 
27442 ripley 6
\name{read.socket}
7
\title{ Read from or Write to a Socket}
8
\usage{
60528 ripley 9
read.socket(socket, maxlen = 256L, loop = FALSE)
27442 ripley 10
write.socket(socket, string)
11
}
56186 murdoch 12
\alias{read.socket}
27442 ripley 13
\alias{write.socket}
14
\arguments{
60528 ripley 15
    \item{socket}{a socket object.}
16
    \item{maxlen}{maximum length (in bytes) of string to read.}
27442 ripley 17
    \item{loop}{wait for ever if there is nothing to read?}
60528 ripley 18
    \item{string}{string to write to socket.}
27442 ripley 19
}
20
\description{
21
    \code{read.socket} reads a string from the specified socket,
22
    \code{write.socket} writes to the specified socket.  There is very
23
    little error checking done by either.
24
}
25
\value{
60528 ripley 26
  \code{read.socket} returns the string read as a length-one character vector.
61433 ripley 27
 
60528 ripley 28
  \code{write.socket} returns the number of bytes written.
29
 
27442 ripley 30
}
31
\author{Thomas Lumley}
32
 
33
\seealso{
34
    \code{\link{close.socket}}, \code{\link{make.socket}}
35
}
36
 
37
\examples{
38
finger <- function(user, host = "localhost", port = 79, print = TRUE)
39
{
40
    if (!is.character(user))
41
        stop("user name must be a string")
42
    user <- paste(user,"\r\n")
43
    socket <- make.socket(host, port)
44
    on.exit(close.socket(socket))
45
    write.socket(socket, user)
46
    output <- character(0)
47
    repeat{
48
        ss <- read.socket(socket)
49
        if (ss == "") break
50
        output <- paste(output, ss)
51
    }
52
    close.socket(socket)
53
    if (print) cat(output)
54
    invisible(output)
55
}
30915 ripley 56
\dontrun{
57
finger("root")  ## only works if your site provides a finger daemon}
27442 ripley 58
}
59
\keyword{misc}