Adapt a socket handle to an R connection. The returned connection can be passed to base R functions such as readBin(), writeBin(), readLines(), and writeLines(). Closing the connection does not close the underlying socket handle; call socket_close() explicitly when the handle is no longer needed.

Uses R's connection dispatch, so this works with socket_connection() and other readable R connections.

Uses R's connection dispatch, so this works with socket_connection() and other writable R connections.

socket_connection(socket, close_socket = FALSE)

socket_connection_read(connection, n = 4096L)

socket_connection_write(connection, data)

Arguments

socket

A socketR socket handle.

close_socket

Whether closing the adapter should also close the underlying socket. The default FALSE preserves adapter-only close behavior.

connection

An open R connection.

n

Maximum number of bytes to read.

data

A raw vector.

Value

An R connection object.

A raw vector, possibly shorter than n at end-of-file.

Number of bytes written.

Examples

s <- socket_create()
con <- socket_connection(s)
close(con)
socket_close(s)