CUGL 3.0
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Public Member Functions | Public Attributes | List of all members
cugl::netcode::WebSocketConfig Class Reference

#include <CUWebSocketConfig.h>

Public Member Functions

 WebSocketConfig ()
 
 WebSocketConfig (uint16_t port)
 
 WebSocketConfig (const InetAddress &address)
 
 WebSocketConfig (const std::shared_ptr< JsonValue > &prefs)
 
 WebSocketConfig (const WebSocketConfig &src)=default
 
 WebSocketConfig (WebSocketConfig &&src)=default
 
 ~WebSocketConfig ()
 
WebSocketConfigoperator= (const WebSocketConfig &src)=default
 
WebSocketConfigoperator= (WebSocketConfig &&src)=default
 
WebSocketConfigset (const WebSocketConfig &src)
 
WebSocketConfigset (const std::shared_ptr< WebSocketConfig > &src)
 
WebSocketConfigset (const std::shared_ptr< JsonValue > &pref)
 

Public Attributes

uint16_t port
 
std::string bindaddr
 
bool secure
 
std::string pemCertificate
 
std::string pemKey
 
std::string pemPass
 
int32_t timeout
 
size_t bufferSize
 
size_t maxMessage
 

Detailed Description

This class represents the configuration for our websocket server

Each WebSocketServer has a configuration that cannot be changed once the server is initialized.. This configuration controls such things as the port, the binding address, the protocol (ws:// vs wss://), and other communication settings. With that said, none of these values are required as they all have defaults.

This class is effectively a simple struct. All attributes are publicly available and we do not use the standard CUGL shared pointer architecture. Internet addresses are designed to be use on the stack, though you can combine them with shared pointers åif you wish.

Constructor & Destructor Documentation

◆ WebSocketConfig() [1/6]

cugl::netcode::WebSocketConfig::WebSocketConfig ( )

Creates a new configuration.

All values will be defaults. The lobby server will be set to 'localhost" at port 8080.

◆ WebSocketConfig() [2/6]

cugl::netcode::WebSocketConfig::WebSocketConfig ( uint16_t  port)

Creates a new configuration with the given port.

All other values will be defaults.

◆ WebSocketConfig() [3/6]

cugl::netcode::WebSocketConfig::WebSocketConfig ( const InetAddress address)

Creates a new configuration with the given bind address.

All other values will be defaults.

◆ WebSocketConfig() [4/6]

cugl::netcode::WebSocketConfig::WebSocketConfig ( const std::shared_ptr< JsonValue > &  prefs)

Creates this configuration using a JSON entry.

The JSON value should be an object. While all keys are optional, it supports the following entries:

 "port":         The port to bind to
 "address":      The local address to bind to
 "secure":       A boolean indicating if the server uses SSL
 "certificate":  Either the PEM certficate, or a path to the certificate
 "pemkey":       Either the PEM key, or a path to the key
 "pempass":      The PEM pass phrase
 "timeout":      An int representing the connection timeout
 "buffer size":  An int respresenting the size of the message buffer
 "max message":  An int respresenting the maximum transmission size
Parameters
prefsThe configuration settings

◆ WebSocketConfig() [5/6]

cugl::netcode::WebSocketConfig::WebSocketConfig ( const WebSocketConfig src)
default

Creates a copy of the configuration.

This copy constructor is provided so that internet addresses may be safely used on the stack, without the use of pointers.

Parameters
srcThe original configuration to copy

◆ WebSocketConfig() [6/6]

cugl::netcode::WebSocketConfig::WebSocketConfig ( WebSocketConfig &&  src)
default

Creates a new configuration with the resources of the given one.

This move constructor is provided so that internet addresses may be used efficiently on the stack, without the use of pointers.

Parameters
srcThe original configuration contributing resources

◆ ~WebSocketConfig()

cugl::netcode::WebSocketConfig::~WebSocketConfig ( )

Deletes this configuration, disposing all resources

Member Function Documentation

◆ operator=() [1/2]

WebSocketConfig & cugl::netcode::WebSocketConfig::operator= ( const WebSocketConfig src)
default

Assigns this configuration to be a copy of the given configuration.

Parameters
srcThe configuration to copy
Returns
a reference to this configuration for chaining purposes.

◆ operator=() [2/2]

WebSocketConfig & cugl::netcode::WebSocketConfig::operator= ( WebSocketConfig &&  src)
default

Assigns this configuration to have the resources of the given configuration.

Parameters
srcThe configuration to take resources from
Returns
a reference to this configuration for chaining purposes.

◆ set() [1/3]

WebSocketConfig & cugl::netcode::WebSocketConfig::set ( const std::shared_ptr< JsonValue > &  pref)

Assigns this configuration according to the given JSON object

The JSON value should be an object. While all keys are optional, it supports the following entries:

 "port":         The port to bind to
 "address":      The local address to bind to
 "secure":       A boolean indicating if the server uses SSL
 "certificate":  Either the PEM certficate, or a path to the certificate
 "pemkey":       Either the PEM key, or a path to the key
 "pempass":      The PEM pass phrase
 "timeout":      An int representing the connection timeout
 "buffer size":  An int respresenting the size of the message buffer
 "max message":  An int respresenting the maximum transmission size
Parameters
prefThe address settings
Returns
a reference to this address for chaining purposes.

◆ set() [2/3]

WebSocketConfig & cugl::netcode::WebSocketConfig::set ( const std::shared_ptr< WebSocketConfig > &  src)

Assigns this configuration to be a copy of the given configuration.

Parameters
srcThe configuration to copy
Returns
a reference to this configuration for chaining purposes.

◆ set() [3/3]

WebSocketConfig & cugl::netcode::WebSocketConfig::set ( const WebSocketConfig src)

Assigns this configuration to be a copy of the given configuration.

Parameters
srcThe configuration to copy
Returns
a reference to this configuration for chaining purposes.

Member Data Documentation

◆ bindaddr

std::string cugl::netcode::WebSocketConfig::bindaddr

The local internet address to bind to (default: "").

If this is empty, then the default local address will be used.

◆ bufferSize

size_t cugl::netcode::WebSocketConfig::bufferSize

The message buffer size (default 0 for automatic)

This value is the number of messages that can be received before a dispatcher must be called. This value is coupled to the maximum message size. If this value is small, then maximum message size may need to be increased to support data throughput.

◆ maxMessage

size_t cugl::netcode::WebSocketConfig::maxMessage

The maximum message size (default 0 for automatic)

This value is the maximum size of a single message, which is one call to a dispatcher. It is coupled to the message buffer size. If this value is smalled, the buffer size may need to be increased to support data throughput.

◆ pemCertificate

std::string cugl::netcode::WebSocketConfig::pemCertificate

The PEM certificate or a path to a file containing the PEM certificate (default: "").

This attribute is only read if secure is true. If the string is empty, the network layer attempts to use an autogenerated certificate.

◆ pemKey

std::string cugl::netcode::WebSocketConfig::pemKey

The PEM key or a path to a file containing the PEM key (default: "").

This attribute is only read if secure is true. If pemCertificate is empty (so the certificate is autogenereated), this should be empty too.

◆ pemPass

std::string cugl::netcode::WebSocketConfig::pemPass

The PEM key passphrase (default: "")

This attribute is only read if secure is true. If there is no passphrase, this should be empty.

◆ port

uint16_t cugl::netcode::WebSocketConfig::port

The server port (default: 8080)

◆ secure

bool cugl::netcode::WebSocketConfig::secure

Whether the websocket requires an SSL connection (default: false)

◆ timeout

int32_t cugl::netcode::WebSocketConfig::timeout

The connection timeout in milliseconds (default 0 for automatic)

The server will drop connections that lag more than the timeout amount. To disable timeouts, set this value to a negative number. Choosing 0 causes the server to use a default timeout.


The documentation for this class was generated from the following file: