All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Public Member Functions | List of all members
net::ServerHandler Class Reference

Server side of the SimDB socket interface. This class provides the server side functions to simplify the incoming connections handling and the messages sending/receiving. More...

#include <ServerHandler.h>

Inheritance diagram for net::ServerHandler:
Inheritance graph
[legend]
Collaboration diagram for net::ServerHandler:
Collaboration graph
[legend]

Public Member Functions

 ServerHandler (net::Port port)
 
bool createSocket ()
 
bool startListening ()
 
int acceptConnection ()
 
std::string receiveMessage (int connectedSocket, SocketState &threadState)
 
void sendMessage (int connectedSocket, const std::string &message, SocketState &threadState)
 
char * receiveFile (int connectedSocket, SocketState &threadState)
 
void closeConnection (int connectedSocket, SocketState &threadState)
 
bool stopService ()
 
- Public Member Functions inherited from net::SocketHandler
 SocketHandler (Port port)
 

Additional Inherited Members

- Static Public Attributes inherited from net::SocketHandler
static const int GENERIC_SOCKET_ERROR = -1
 
static const int DEFAULT_SOCKET_DESCRIPTOR = -1
 
static const Port DEFAULT_INVALID_PORT = -1
 
- Protected Member Functions inherited from net::SocketHandler
int getLastErrorCode ()
 
bool closeSocket (int descriptor)
 
- Protected Attributes inherited from net::SocketHandler
Port serverPort
 
SocketState currentState
 
- Static Protected Attributes inherited from net::SocketHandler
static const int MESSAGE_BUFFER_SIZE = 8192
 
static const char END_OF_MESSAGE = 3
 

Detailed Description

Server side of the SimDB socket interface. This class provides the server side functions to simplify the incoming connections handling and the messages sending/receiving.

Member Function Documentation

int ServerHandler::acceptConnection ( )
Returns
The Socket descriptor of the connection just accepted, or the GENERIC_SOCKET_ERROR macro if something is wrong.
void ServerHandler::closeConnection ( int  connectedSocket,
SocketState threadState 
)

Chiude una connessione con un certo client

Parameters
connectedSocketThe socket with the client connection.
threadStateState of the thread which handles the connection.
bool ServerHandler::createSocket ( )
Returns
true if the socket creation succeeds (through the socket() function), false otherwise.
char * ServerHandler::receiveFile ( int  connectedSocket,
SocketState threadState 
)
Parameters
connectedSocketThe socket with the client connection.
threadStateState of the thread which handles the connection.
Returns
Pointer to the base64-encoded file. We use a pointer for efficiency reasons.
string ServerHandler::receiveMessage ( int  connectedSocket,
SocketState threadState 
)

Receive a message from the client.

Parameters
connectedSocketThe socket whit the client connection.
threadStateState of the thread which handles the connection.
Returns
String with a message send by the client.
void ServerHandler::sendMessage ( int  connectedSocket,
const std::string &  message,
SocketState threadState 
)
Parameters
connectedSocketThe socket with the client connection.
messageThe message to send to the client.
threadStateState of the thread which handles the connection.
bool ServerHandler::startListening ( )
Returns
true if the socket is ready to accept connection requests (through the bind() and listen() functions), false otherwise.
bool ServerHandler::stopService ( )

Close the listening socket and stop the server communication service.

Returns
true if the operation succeeds, false otherwise.

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