Closed yogesh-bansal closed 4 years ago
Very late answer, ... but I am afraid I don't understand what you want here. You should understand that the svSocket socket server is sharing .GlobalEnv between the different clients. This is a feature, on the contrary to, say Rserve, that creates a different workspace for each client. With svSocket, you really work together in the same session. But then, you should be very careful when you want to do complex things, because results may be very strange.
One scenario where this is useful, is when a client is just inspecting/monitoring an R session, but does not change anything there. It seems to be the case with your toy example, although your example really does nothing useful. So, my confusion!
What I wanted was basically to have an option in evalServer function so that instead for waiting for results, we just send the command to the server and return to the client session immediately, instead of having the client session busy until the command is processed on server side. It was useful in a special case in which I didn't want the results back in client session, while the client session was only used to trigger an API call on the server-side which handles some IoT stuff.
Though I was able to have it by writing a copy of the evalServer function and just by cutting the code at line 128 in https://github.com/SciViews/svSocket/blob/master/R/evalServer.R
Ah OK, now I understand. Have you read the man page for ?processSocket
, especially this paragraph:
"The sequence <<>> at the beginning of a command indicates that the server wants to disconnect once the command is fully treated by R. Similarly, the sequence <<
>> tells the server to disconnect the client before processing the command (no error message is returned to the client!)."
I think this is what you are looking for. So, prepend you command with <<<Q>>>
and you will be disconnected as soon as your command is received and before the server processes it.
Problem Version 1, Can we make pr_fun process it's retun without waiting for ch_fun() to finish
ch_fun <- function() {Sys.sleep(10)} pr_fun <- function() {ch_fun(); return("Done")} pr_fun() Proble Actual Version
R session 1 as svSocket Server
library(svSocket) startSocketServer(port = 9875,local=FALSE) R session 2 as svSocket client
con <- socketConnection(port = 9875,host="127.0.0.1") evalServer(con,"Sys.sleep(20)") R session 3 as svSocket client
con <- socketConnection(port = 9875,host="127.0.0.1") evalServer(con,"a=10") If we run the code lines for session 2 and while server is processing Sys.sleep call we quickly put the code lines for session 3 in session 3 and abort the call it still gets processed. We can check that on server side by checking if object "a" was created.
My point is we didn't have to wait for job to finish in session 3 still it was processed so somehow jobs were piled up on session side and we don't have to wait for jobs to finish just send them to server and abort the waiting process and move ahead. We can manually abort using Ctrl+C or Esc but how can I do that in a function. I want pr_fun to call ch_fun in server session and proceed to its return immediately.