b1_sendrecvfile: File Transfer Functions

File Transfer FunctionsR Documentation

File Transfer Functions

Description

High level functions calling zmq_send() and zmq_recv() to transfer a file in 200 KiB chunks.

Usage

zmq.sendfile(
  port,
  filename,
  verbose = FALSE,
  flags = ZMQ.SR()$BLOCK,
  forcebin = FALSE,
  ctx = NULL,
  socket = NULL
)

zmq.recvfile(
  port,
  endpoint,
  filename,
  verbose = FALSE,
  flags = ZMQ.SR()$BLOCK,
  forcebin = FALSE,
  ctx = NULL,
  socket = NULL
)

Arguments

port

A valid tcp port.

filename

The name (as a string) of the in/out files. The in and out file names can be different.

verbose

Logical; determines if a progress bar should be shown.

flags

A flag for the method used by zmq_sendfile and zmq_recvfile

forcebin

Force to read/send/recv/write in binary form. Typically for a Windows system, text (ASCII) and binary files are processed differently. If TRUE, "r+b" and "w+b" will be enforced in the C code. This option is mainly for Windows.

ctx

A ZMQ ctx. If NULL (default), the function will initial one at the beginning and destroy it after finishing file transfer.

socket

A ZMQ socket based on ctx. If NULL (default), the function will create one at the beginning and close it after finishing file transfer.

endpoint

A ZMQ socket endpoint.

Details

If no socket is passed, then by default zmq.sendfile() binds a ZMQ_PUSH socket, and zmq.recvfile() connects to this with a ZMQ_PULL socket. On the other hand, a PUSH/PULL, REQ/REP, or REP/REQ socket pairing may be passed. In that case, the socket should already be connected to the desired endpoint. Be careful not to pass the wrong socket combination (e.g., do not do REQ/REQ), as this can put the processes in an un-recoverable state.

Value

zmq.sendfile() and zmq.recvfile() return number of bytes (invisible) in the sent message if successful, otherwise returns -1 (invisible) and sets errno to the error value, see ZeroMQ manual for details.

Author(s)

Drew Schmidt and Christian Heckendorf

References

ZeroMQ/4.1.0 API Reference: https://libzmq.readthedocs.io/en/zeromq4-1/

Programming with Big Data in R Website: https://pbdr.org/

See Also

zmq.msg.send(), zmq.msg.recv().

Examples

## Not run: 
### Run the sender and receiver code in separate R sessions.

# Receiver
library(pbdZMQ, quietly = TRUE)
zmq.recvfile(55555, "localhost", "/tmp/outfile", verbose=TRUE)

# Sender
library(pbdZMQ, quietly = TRUE)
zmq.sendfile(55555, "/tmp/infile", verbose=TRUE)

## End(Not run)


snoweye/pbdZMQ documentation built on Jan. 27, 2024, 11:35 a.m.