Create a socket connection
Usage
make.socket(host="localhost", port, fail=T, server=F)
close.socket(socket)
Arguments
host
|
name of remote host
|
port
|
port to connect to/listen on
|
fail
|
Failure to connect is an error?
|
server
|
A server socket?
|
Description
With server=F
attempts to open a client socket to the specified
port and host. With server=T
listens on the specified port for a
connection and then returns a server socket. It's a good idea to use
on.exit
to ensure that a socket is closed, as you only
get 64 of them.Value
An object of "class socket"
socket
|
Socket number. This is for internal use
|
port
|
port number of the connection
|
host
|
name of remote computer
|
WARNING
I don't know if the connecting host name returned
when server=T
can be trusted. I suspect not.References
Adapted from Luke Tierney's code for XLISP-Stat, in turn
based on code from Robbins and Robbins "Practical UNIX Programming"See Also
close.socket
,read.socket
,write.socket
Examples
daytime<-function(host="localhost"){
a<-make.socket(host,13)
on.exit(close.socket(a))
read.socket(a)
}
daytime() ## only works if your computer runs this service
daytime("chime.cac.washington.edu")