read.socket

0th

Percentile

Read from or Write to a Socket

read.socket reads a string from the specified socket, write.socket writes to the specified socket. There is very little error checking done by either.

Keywords
misc
Usage
read.socket(socket, maxlen = 256L, loop = FALSE)
write.socket(socket, string)
Arguments
socket
a socket object.
maxlen
maximum length (in bytes) of string to read.
loop
wait for ever if there is nothing to read?
string
string to write to socket.
Value

read.socket returns the string read as a length-one character vector. write.socket returns the number of bytes written.

See Also

close.socket, make.socket

Aliases
  • read.socket
  • write.socket
Examples
library(utils) finger <- function(user, host = "localhost", port = 79, print = TRUE) { if (!is.character(user)) stop("user name must be a string") user <- paste(user,"\r\n") socket <- make.socket(host, port) on.exit(close.socket(socket)) write.socket(socket, user) output <- character(0) repeat{ ss <- read.socket(socket) if (ss == "") break output <- paste(output, ss) } close.socket(socket) if (print) cat(output) invisible(output) } ## Not run: ------------------------------------ # finger("root") ## only works if your site provides a finger daemon ## ---------------------------------------------
Documentation reproduced from package utils, version 3.3.2, License: Part of R 3.3.2

Community examples

Looks like there are no examples yet.