Learn R Programming

streamConnect (version 0.0-4)

publish_DSD_via_Socket: Write a Stream to a Socket

Description

Use a write_stream() to write data to a socket connection.

Usage

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

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

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

Provide access to a data stream using a local port.

Blocking: The DSD will be blocked once the buffer is full and resume producing data when it gets unblocked.

This method does not provide a header.

See Also

Other Socket: DSD_ReadSocket()

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

Examples

Run this code
# 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

Run the code above in your browser using DataLab