1% File src/library/utils/man/make.socket.Rd 2% Part of the R package, https://www.R-project.org 3% Copyright 1995-2015 R Core Team 4% Distributed under GPL 2 or later 5 6\name{make.socket} 7\alias{make.socket} 8\alias{print.socket} 9\title{Create a Socket Connection} 10\usage{ 11make.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 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. 25} 26\value{ 27 An object of class \code{"socket"}, a list with components: 28 \item{socket}{socket number. This is for internal use. On a 29 Unix-alike it is a file descriptor.} 30 \item{port}{port number of the connection.} 31 \item{host}{name of remote computer.} 32} 33\author{Thomas Lumley} 34\references{ 35 Adapted from Luke Tierney's code for \code{XLISP-Stat}, in turn 36 based on code from Robbins and Robbins \dQuote{Practical UNIX Programming}. 37} 38\section{Warning}{ 39 I don't know if the connecting host name returned 40 when \code{server = TRUE} can be trusted. I suspect not. 41} 42 43\seealso{ 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. 48} 49 50\examples{ 51daytime <- function(host = "localhost"){ 52 a <- make.socket(host, 13) 53 on.exit(close.socket(a)) 54 read.socket(a) 55} 56## Official time (UTC) from US Naval Observatory 57\dontrun{daytime("tick.usno.navy.mil")} 58} 59\keyword{misc} 60