diff options
author | TinWoodman92 <chrhodgden@gmail.com> | 2023-06-25 07:55:58 -0500 |
---|---|---|
committer | TinWoodman92 <chrhodgden@gmail.com> | 2023-06-25 07:55:58 -0500 |
commit | 126c31f0da53d1d9be67291feb41ebe4aaa2c704 (patch) | |
tree | ed5e1f9c279bde696c5e3f2699e2d604c5ac0bc8 /dialoguer/context_script.r | |
parent | 598b04dcfa114ea4733b00f13c4974c87bf9d148 (diff) |
Pass uuid and taget file path via system arguments. Establish socket connection by verifying matching uuid.
Diffstat (limited to 'dialoguer/context_script.r')
-rw-r--r-- | dialoguer/context_script.r | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/dialoguer/context_script.r b/dialoguer/context_script.r index bb2b133..9c600f5 100644 --- a/dialoguer/context_script.r +++ b/dialoguer/context_script.r @@ -3,13 +3,8 @@ PORT <- 6011 SERVER <- "localhost" FORMAT <- "utf-8" DISCONNECT_MESSAGE <- "!DISSCONNECT" - -con <- socketConnection( - host = SERVER, - port = PORT, - server = FALSE, - open = "a+b" -) +UUID <- commandArgs(trailingOnly = TRUE)[1] +TARGET_FILE <- commandArgs(trailingOnly = TRUE)[2] data_type_vect <- c( character = 'character', @@ -95,13 +90,30 @@ recv <- function(conn, recv_data_type = FALSE, set_data_type = "character") { return(data) } -#receive target file path -# need to learn how to receive path as system argument. -# may also receive package directory to source-import R modules -file_path <- recv(con) +find_connection <- function() { + connected <- FALSE + while (!connected) { + con <- socketConnection( + host = SERVER, + port = PORT, + server = FALSE, + open = "a+b" + ) + + send(con, UUID) + uuid_chk <- recv(con) + connected <- (UUID == uuid_chk) + if (!connected) { + close(con) + } + } + return(con) +} + +con <- find_connection() #load target file -source(file_path) +source(TARGET_FILE) confirm <- TRUE msg <- 'confirm' |