publish_DSD_via_Socket: Publish a Data Stream using a Socket

View source: R/publish_DSD_via_Socket.R

publish_DSD_via_SocketR Documentation

Publish a Data Stream using a Socket

Description

Creates a socket server connection to send steam data.

Usage

publish_DSD_via_Socket(dsd, port, blocksize = 1024L, background = TRUE, ...)

Arguments

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 socketConnection().

Details

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.

Value

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).

See Also

Other Socket: DSD_ReadSocket()

Other dsd: DSD_ReadSocket(), DSD_ReadWebService(), publish_DSD_via_WebService()

Examples

# 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

streamConnect documentation built on June 22, 2024, 9:55 a.m.