View source: R/publish_DSD_via_Socket.R
publish_DSD_via_Socket | R Documentation |
Creates a socket server connection to send steam data.
publish_DSD_via_Socket(dsd, port, blocksize = 1024L, background = TRUE, ...)
dsd |
A DSD object. |
port |
port used to serve the DSD. |
blocksize |
number of data points pushed on the buffer at once. |
background |
logical; start a background process? |
... |
further arguments are passed on to |
Creates a server socket with socketConnection()
and then uses a stream::write_stream()
to write data to a socket connection.
This method does not provide a header for the data.
a processx::process object created with callr::r_bg()
which runs the plumber server
in the background. The process can be stopped with rp$kill()
or by killing the process
using the operating system with the appropriate PID. rp$get_result()
can
be used to check for errors in the server process (e.g., when it terminates
unexpectedly).
Other Socket:
DSD_ReadSocket()
Other dsd:
DSD_ReadSocket()
,
DSD_ReadWebService()
,
publish_DSD_via_WebService()
# find a free port
port <- httpuv::randomPort()
port
# create a background DSD process sending data to the port
rp1 <- DSD_Gaussians(k = 3, d = 3) %>% publish_DSD_via_Socket(port = port)
rp1
# connect to the port (retry waits for the socket to establish)
con <- retry(socketConnection(port = port, open = 'r'))
dsd <- retry(DSD_ReadStream(con, col.names = c("x", "y", "z", ".class")))
get_points(dsd, n = 10)
plot(dsd)
# close connection
close_stream(dsd)
# end the DSD process. Note: that closing the connection above
# may already kill the process.
rp1$kill()
rp1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.