| 42333 |
ripley |
1 |
% File src/library/utils/man/make.socket.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 68912 |
ripley |
3 |
% Copyright 1995-2015 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{
|
| 68912 |
ripley |
44 |
\code{\link{close.socket}}, \code{\link{read.socket}}.
|
|
|
45 |
|
|
|
46 |
Compiling in support for sockets was optional prior to \R 3.3.0: see
|
|
|
47 |
\code{\link{capabilities}("sockets")} to see if it is available.
|
| 27442 |
ripley |
48 |
}
|
|
|
49 |
|
|
|
50 |
\examples{
|
|
|
51 |
daytime <- function(host = "localhost"){
|
|
|
52 |
a <- make.socket(host, 13)
|
|
|
53 |
on.exit(close.socket(a))
|
|
|
54 |
read.socket(a)
|
|
|
55 |
}
|
| 40281 |
ripley |
56 |
## Official time (UTC) from US Naval Observatory
|
| 27442 |
ripley |
57 |
\dontrun{daytime("tick.usno.navy.mil")}
|
|
|
58 |
}
|
|
|
59 |
\keyword{misc}
|