Need help on named pipes on Windows

Hi All,

Not able to make the below code work. Getting Error in readLines(serverPipe) : invalid connection.

Please help.

serverPipe <- pipe("\\\\.\\pipe\\mserver", open = 'r', "UTF-8")

if (serverPipe)
{
  print(serverPipe)

  while(TRUE)
    {
        Sys.sleep(1)

        message  <- readLines(serverPipe)

      if(length(message)) print(message, stdout())


      if(all(message == "client closing"))
      {
        close(serverPipe)
      }
    }
}

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue and provide a little more information about what are you trying to achieve with this code? Please have a look at this guide, to see how to create a reprex:

Hi,

Thanks for letting me know how to post here.

Regards

Hi,

I am trying to open a named pipe connection on Windows 7 and it is not working. Please help.

serverPipe <- pipe("\\\\.\\pipe\\mserver", open = 'r', "UTF-16")

if (serverPipe)
{
  print(serverPipe)
  str(serverPipe)
  
  message <- ""
  
  while(TRUE)
    {
        Sys.sleep(1)

        message  <- readLines(serverPipe)

      if(length(message)) print(message)

      if(all(message == "client closing"))
      {
        close(serverPipe)
      }
    }
}
#> A connection with                                  
#> description "\\\\.\\pipe\\mserver"
#> class       "pipe"                
#> mode        "r"                   
#> text        "text"                
#> opened      "opened"              
#> can read    "yes"                 
#> can write   "no"                  
#>  'pipe' int 4
#>  - attr(*, "conn_id")=<externalptr>
#> Warning in readLines(serverPipe): line 1 appears to contain an embedded nul
#> Error in readLines(serverPipe): invalid connection

Created on 2019-05-27 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.