Learn R Programming

nanonext (version 0.2.0)

socket: Open Socket

Description

Open a Socket implementing 'protocol', and optionally dial or listen at an address.

Usage

socket(
  protocol = c("pair", "bus", "push", "pull", "req", "rep", "pub", "sub", "surveyor",
    "respondent"),
  dial = NULL,
  listen = NULL,
  autostart = TRUE
)

Arguments

protocol

[default 'pair'] choose protocol - 'pair', 'bus', 'push', 'pull', 'req', 'rep', 'pub', 'sub', 'surveyor', or 'respondent' - see protocols.

dial

(optional) a URL to dial, specifying the transport and address as a character string e.g. 'inproc://anyvalue' or 'tcp://127.0.0.1:5555' (see transports).

listen

(optional) a URL to listen at, specifying the transport and address as a character string e.g. 'inproc://anyvalue' or 'tcp://127.0.0.1:5555' (see transports).

autostart

[default TRUE] whether to start the dialer/listener. Set to FALSE if you wish to set configuration options on the dialer/listener as it is not generally possible to change these once started.

Value

A Socket (object of class 'nanoSocket' and 'nano').

Protocols

The following communications patterns are implemented:

  • Pair (two-way radio) - protocol: 'pair'

  • Bus (routing) - protocol: 'bus'

  • Pipeline (one-way pipe) - protocol: 'push', 'pull'

  • Request/Reply (I ask, you answer) - protocol: 'req', 'rep'

  • Publisher/Subscriber (topics & broadcast) - protocol: 'pub', 'sub'

  • Survey (everyone votes) - protocol: 'surveyor', 'respondent'

Please see protocols for further documentation.

Details

NNG presents a socket view of networking. The sockets are constructed using protocol-specific functions, as a given socket implements precisely one protocol.

Each socket can be used to send and receive messages (if the protocol supports it, and implements the appropriate protocol semantics). For example, sub sockets automatically filter incoming messages to discard those for topics that have not been subscribed.

This function (optionally) binds a single Dialer and/or Listener to a Socket. More complex network topologies may be created by binding further Dialers/Listeners to the Socket as required using dial and listen. New contexts can also be created using context if the protocol supports it.

Examples

Run this code
# NOT RUN {
socket <- socket("pair")
socket
close(socket)

# }

Run the code above in your browser using DataLab