Provide a socket listener and the ability to send data to connected partners. More...
#include <SockServ.h>
Public Member Functions | |
SockServ (uint16_t port) | |
Create an instance of the class. More... | |
SockServ () | |
~SockServ () | |
int | connectedCount () |
Determine the number of connected partners. More... | |
void | disconnect (Socket s) |
Disconnect any connected partners. | |
bool | getSSL () |
size_t | receiveData (Socket s, void *pData, size_t maxData) |
Wait for data. More... | |
void | sendData (uint8_t *data, size_t length) |
Send data to any connected partners. More... | |
void | sendData (std::string str) |
Send data from a string to any connected partners. More... | |
void | setPort (uint16_t port) |
Set the port number to use. More... | |
void | setSSL (bool use=true) |
void | start () |
Start listening for new partner connections. More... | |
void | stop () |
Stop listening for new partner connections. | |
Socket | waitForData (std::set< Socket > &socketSet) |
Socket | waitForNewClient () |
Wait for a client connection to be present. Returns when a client connection is present. This can block until a client connects or can return immediately is there is already a client connection in existence. | |
Provide a socket listener and the ability to send data to connected partners.
We use this class to listen on a given socket and accept connections from partners. When we call one of the sendData() methods, the data passed as parameters is then sent to the connected partners.
Here is an example code fragment that uses the class:
SockServ::SockServ | ( | uint16_t | port | ) |
Create an instance of the class.
We won't actually start listening for clients until after the start() method has been called.
[in] | port | The TCP/IP port number on which we will listen for incoming connection requests. |
SockServ::SockServ | ( | ) |
Constructor
SockServ::~SockServ | ( | ) |
Destructor
int SockServ::connectedCount | ( | ) |
Determine the number of connected partners.
bool SockServ::getSSL | ( | ) |
Get the SSL status.
size_t SockServ::receiveData | ( | Socket | s, |
void * | pData, | ||
size_t | maxData | ||
) |
Wait for data.
[in] | pData | Pointer to buffer to hold the data. |
[in] | maxData | Maximum size of the data to receive. |
void SockServ::sendData | ( | uint8_t * | data, |
size_t | length | ||
) |
Send data to any connected partners.
[in] | data | A sequence of bytes to send to the partner. |
[in] | length | The length of the sequence of bytes to send to the partner. |
void SockServ::sendData | ( | std::string | str | ) |
Send data from a string to any connected partners.
[in] | str | A string from which sequence of bytes will be used to send to the partner. |
void SockServ::setPort | ( | uint16_t | port | ) |
Set the port number to use.
port | The port number to use. |
void SockServ::start | ( | ) |
Start listening for new partner connections.
The port number on which we will listen is the one defined when the class was created.