My Project
 All Classes Functions Variables Pages
Public Member Functions | List of all members
SockServ Class Reference

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.
 

Detailed Description

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 mySockServer = SockServ(9876);
mySockServer.start();
// Later ...
mySockServer.sendData(data, dataLen);

Constructor & Destructor Documentation

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.

Parameters
[in]portThe TCP/IP port number on which we will listen for incoming connection requests.
SockServ::SockServ ( )

Constructor

SockServ::~SockServ ( )

Destructor

Member Function Documentation

int SockServ::connectedCount ( )

Determine the number of connected partners.

Returns
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.

Parameters
[in]pDataPointer to buffer to hold the data.
[in]maxDataMaximum size of the data to receive.
Returns
The amount of data returned or 0 if there was an error.
void SockServ::sendData ( uint8_t *  data,
size_t  length 
)

Send data to any connected partners.

Parameters
[in]dataA sequence of bytes to send to the partner.
[in]lengthThe 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.

Parameters
[in]strA 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.

Parameters
portThe 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.


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