Skip to content

Instantly share code, notes, and snippets.

@corynissen
Last active April 16, 2020 14:23
Show Gist options
  • Save corynissen/5659929 to your computer and use it in GitHub Desktop.
Save corynissen/5659929 to your computer and use it in GitHub Desktop.
R socket client example
client <- function(){
while(TRUE){
con <- socketConnection(host="localhost", port = 6011, blocking=TRUE,
server=FALSE, open="r+")
f <- file("stdin")
open(f)
print("Enter text to be upper-cased, q to quit")
sendme <- readLines(f, n=1)
if(tolower(sendme)=="q"){
break
}
write_resp <- writeLines(sendme, con)
server_resp <- readLines(con, 1)
print(paste("Your upper cased text: ", server_resp))
close(con)
}
}
client()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment