The R Project SVN R

Rev

Rev 60531 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42333 ripley 1
% File src/library/utils/man/make.socket.Rd
2
% Part of the R package, http://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{make.socket}
56186 murdoch 7
\alias{make.socket}
27442 ripley 8
\alias{print.socket}
9
\title{Create a Socket Connection}
10
\usage{
11
make.socket(host = "localhost", port, fail = TRUE, server = FALSE)
12
}
13
\arguments{
14
  \item{host}{name of remote host}
15
  \item{port}{port to connect to/listen on}
16
  \item{fail}{failure to connect is an error?}
17
  \item{server}{a server socket?}
18
}
19
\description{
20
  With \code{server = FALSE} attempts to open a client socket to the
60528 ripley 21
  specified port and host.  With \code{server = TRUE} the \R process
22
  listens on the specified port for a connection and then returns a
23
  server socket.  It is a good idea to use \code{\link{on.exit}} to
24
  ensure that a socket is closed, as you only get 64 of them.
27442 ripley 25
}
26
\value{
60528 ripley 27
  An object of class \code{"socket"}, a list with components:
60531 ripley 28
  \item{socket}{socket number.  This is for internal use.  On a
29
    Unix-alike it is a file descriptor.}
60528 ripley 30
  \item{port}{port number of the connection.}
31
  \item{host}{name of remote computer.}
27442 ripley 32
}
33
\author{Thomas Lumley}
34
\references{
35
  Adapted from Luke Tierney's code for \code{XLISP-Stat}, in turn
60528 ripley 36
  based on code from Robbins and Robbins \dQuote{Practical UNIX Programming}.
27442 ripley 37
}
38
\section{Warning}{
39
  I don't know if the connecting host name returned
60528 ripley 40
  when \code{server = TRUE} can be trusted.  I suspect not.
61433 ripley 41
}
27442 ripley 42
 
43
\seealso{
44
  \code{\link{close.socket}}, \code{\link{read.socket}}
45
}
46
 
47
\examples{
48
daytime <- function(host = "localhost"){
49
    a <- make.socket(host, 13)
50
    on.exit(close.socket(a))
51
    read.socket(a)
52
}
40281 ripley 53
## Official time (UTC) from US Naval Observatory
27442 ripley 54
\dontrun{daytime("tick.usno.navy.mil")}
55
}
56
\keyword{misc}