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{make.socket}
2
\alias{make.socket}
3
\alias{print.socket}
4
\title{Create a Socket Connection}
5
\usage{
6
make.socket(host = "localhost", port, fail = TRUE, server = FALSE)
7
}
8
\arguments{
9
  \item{host}{name of remote host}
10
  \item{port}{port to connect to/listen on}
11
  \item{fail}{failure to connect is an error?}
12
  \item{server}{a server socket?}
13
}
14
\description{
15
  With \code{server = FALSE} attempts to open a client socket to the
16
  specified port and host. With \code{server = TRUE} listens on the
17
  specified port for a connection and then returns a server socket. It is
18
  a good idea to use \code{\link{on.exit}} to ensure that a socket is
19
  closed, as you only get 64 of them.
20
}
21
\value{
22
  An object of class \code{"socket"}.
23
  \item{socket}{socket number. This is for internal use}
24
  \item{port}{port number of the connection}
25
  \item{host}{name of remote computer}
26
}
27
\author{Thomas Lumley}
28
\references{
29
  Adapted from Luke Tierney's code for \code{XLISP-Stat}, in turn
30
  based on code from Robbins and Robbins "Practical UNIX Programming"
31
}
32
\section{Warning}{
33
  I don't know if the connecting host name returned
34
  when \code{server = TRUE} can be trusted. I suspect not.
35
} 
36
 
37
\seealso{
38
  \code{\link{close.socket}}, \code{\link{read.socket}}
39
}
40
 
41
\examples{
42
daytime <- function(host = "localhost"){
43
    a <- make.socket(host, 13)
44
    on.exit(close.socket(a))
45
    read.socket(a)
46
}
47
## Offical time (UTC) from US Naval Observatory
48
\dontrun{daytime("tick.usno.navy.mil")}
49
}
50
\keyword{misc}