listen {beakr} | R Documentation |
Listen for connections on a Beakr instance
Description
Binds and listens for connections at the specified host and port.
Usage
listen(
beakr = NULL,
host = "127.0.0.1",
port = 25118,
daemon = FALSE,
verbose = FALSE
)
Arguments
beakr |
|
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
|
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:
> match(c("b","e","a","k","r"), letters) %% 10 [1] 2 5 1 1 8
Examples
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)