Created
March 21, 2023 18:50
-
-
Save MattSandy/2c299109cf57f7cc22083d1402443a56 to your computer and use it in GitHub Desktop.
R Socket Sending Bin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
con <- socketConnection( | |
host="localhost", | |
port = 6011, | |
blocking=TRUE, | |
server=FALSE, | |
open="r+" | |
) | |
the_data <- "testing this dang thing" | |
write_resp <- writeLines(as.character(nchar(the_data)), con) | |
server_resp <- readLines(con, 1) | |
print(server_resp) | |
if(server_resp=="Ready") { | |
close(con) | |
con <- socketConnection( | |
host="localhost", | |
port = 6011, | |
blocking=TRUE, | |
server=FALSE, | |
open="wb" | |
) | |
write_resp <- writeLines(the_data, con) | |
close(con) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server <- function(){ | |
bytes <- 0 | |
con <- socketConnection( | |
host="localhost", | |
port = 6011, | |
blocking=TRUE, | |
server=TRUE, | |
open="r+" | |
) | |
data <- readLines(con, 1) | |
bytes <- as.numeric(data) | |
print(bytes) | |
response <- "Ready" | |
writeLines(response, con) | |
close(con) | |
con <- socketConnection( | |
host="localhost", | |
port = 6011, | |
blocking=TRUE, | |
server=TRUE, open = "rb" | |
) | |
data <- readBin(con,"raw",n = bytes) | |
print(data) | |
close(con) | |
} | |
server() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment