Git Product home page Git Product logo

svsocket's Introduction

svSocket

R-CMD-check Win Build Status Coverage Status CRAN Status License Life cycle stable

A socket server that allows for another process to connect to R and to interact with it as if it was at the command line directly.

Installation

The latest stable version of {svSocket} can simply be installed from CRAN:

install.packages("svSocket")

You can also install the latest development version. Make sure you have the {remotes} R package installed:

install.packages("remotes")

Use install_github() to install the {svSocket} package from Github (source from master branch will be recompiled on your machine):

remotes::install_github("SciViews/svSocket")

R should install all required dependencies automatically, and then it should compile and install {svSocket}.

Latest devel version of {svSocket} (source + Windows binaries for the latest stable version of R at the time of compilation) is also available from appveyor.

Further explore {svSocket}

You can get further help about this package this way: Make the {svSocket} package available in your R session:

library("svSocket")

Get help about this package:

library(help = "svSocket")
help("svSocket-package")
vignette("svSocket") # None is installed with install_github()

For further instructions, please, refer to these help pages at https://www.sciviews.org/svSocket/.

Code of Conduct

Please note that the {svSocket} project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Note to developers

This package used to be developed on R-Forge in the past. However, the latest R-Forge version was moved to this Github repository on 2016-03-18 (SVN version 569). Please, do not use R-Forge anymore for SciViews development, use this Github repository instead.

svsocket's People

Contributors

adamryczkowski avatar phgrosjean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

svsocket's Issues

Allow using incomplete lines

In vscDebugger/websocket (more specifically here) I am trying to use this package to handle requests sent by a debug client and send back responses via a tcp socket.

As far as I understand, the functions from this package handle messages only line by line. Unfortunately, the messages specified in the Debug Adapter Protocol are not terminated with line breaks, so this approach did not work out of the box.

I tried to modify svSocket here to also read incomplete messages and it seems to work, but I don't know enough about tcl to know if these changes are a good way to achieve this.

Is reading/writing incomplete lines a feature you would consider implementing?

Error when attempting to grab an object from server using evalServer().

This issue seems to be specific to running the svSocket server as as a "job" within Rstudio. Running the server via Rscript (CLI) or another instance of Rstudio works fine.

I receive the following error when I attempt to grab an object from the socket server (running as a "job" within Rstudio):

> evalServer(con2, stream_tbl) 
[1] "Error in eval(parse(text = \"stream_tbl\")) : object 'stream_tbl' not found\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in eval(parse(text = "stream_tbl")): object 'stream_tbl' not found>

I incorporated some ls() checks into my server script, and the stream_tbl object is definitely present in the environment. As mentioned above, everything works fine if I execute the server script using Rscript (CLI) or open up another instance of Rstudio and execute the script. Is there a obvious solution to this? I can post an MWE if needed.

Peter

svSocket and R-devel: possible bug

Hi,
I am writing to inform you that a possible bug has been detected in the svSocket (1.0.2) package in the R-devel version (4.2.0). I tested it on three machines: 1) my local Windows 10 machine; 2) virtual machine with Windows Server 2019 on AWS; 3) virtual machine with Windows 10 professional on Azure platform.

The error message is:
Error in assign("last.warning", last.warning, envir = baseenv()) :
cannot add binding of 'last.warning' to the base environment

About two years ago a similar error message was detected in Microsoft R Open and the problem was solved with the instruction that can be seen (see attached figure: svSocket_R_devel_bug
) in line 33 of the info.R file which is open in Tinn-R . However, it is not working for R-devel.

Workaround bug: MRO and svSocket
unlockBinding("last.warning",
              baseenv())

Is it possible to know if the bug is in R or in the svSocket package? How to fix?

Need an example of a custom procfun

I'm trying to write a custom server. The input and output are large JSON objects, so I thought the best solution was to write a custom procfun so I didn't need to worry about escaping quotes.

Here is my test code:

library(svSocket)

processTestSocket <-
function (msg, socket, serverport, ...) 
{
    cat("Message was:",msg,"\n")
    output <- paste0("message:",msg)
    return(output)
}

options(debug.Socket=TRUE)
startSocketServer(port=12525,server.name="EAServer",
                  procfun=processTestSocket)

This returns TRUE in the console.

However, when I try to test the port using telnet, it closes immediately.

$ telnet localhost 12525
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
$ sudo ss -l |fgrep 12525
tcp   LISTEN 0      4096                                                                                  0.0.0.0:12525                      0.0.0.0:*          
tcp   LISTEN 0      4096                                                                                     [::]:12525                         [::]:*          
$

What am I missing?

svSocket evalServer skip waiting process

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.