listen: Listen for connections on a Beakr instance

Description Usage Arguments Details Value Note Examples

View source: R/utils.R

Description

Binds and listens for connections at the specified host and port.

Usage

1
2
3
4
5
6
7
listen(
  beakr = NULL,
  host = "127.0.0.1",
  port = 25118,
  daemon = FALSE,
  verbose = FALSE
)

Arguments

beakr

Beakr instance.

host

String that is a valid IPv4 or IPv6 address to listen on. Defaults to the local host ("127.0.0.1").

port

Number or integer that indicates the port to listen on. Default is a port opened on 25118.

daemon

Logical specifying whether the server should be run in the background.

verbose

Logical specifying whether to print out details of the Beakr instance now running. This should only be used when running a beaker app interactively, not in production.

Details

listen() binds the specified host and port and listens for connections on a thread. The thread handles incoming requests. when it receives an HTTP request, it will schedule a call to the user-defined middleware and handle the request.

If daemon = TRUE, listen() binds the specified port and listens for connections on a thread running in the background.

See the httpuv package for more details.

Value

A Beakr instance with an active server.

Note

The default port number 25118 was generated using:

1
2
> match(c("b","e","a","k","r"), letters) %% 10
[1] 2 5 1 1 8

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(beakr)

# Create an new Beakr instance
beakr <- newBeakr()

# beakr pipeline
beakr %>%

  httpGET("/", function(req, res, err) {
    return("Successful GET request!\n")
  }) %>%

  listen(daemon = TRUE)     # run in the background

# Stop the server
stopServer(beakr)

beakr documentation built on April 7, 2021, 1:06 a.m.