Public Types | |
enum | modeConnect { NONE, CLIENT, SERVER } |
Public Member Functions | |
ConnectionMgr () | |
virtual | ~ConnectionMgr () |
modeConnect | getMode () const |
void | changeMode (modeConnect) |
void | disconnect (const Socket *partner) |
void | clearConnections () |
Socket * | getSocket () const |
Client mode | |
void | connectTo (const std::string &server, unsigned int port) throw (YGP::CommError) |
void | connectTo (const char *server, unsigned int port) throw (YGP::CommError) |
Server mode | |
void | listenAt (unsigned int port) throw (YGP::CommError) |
int | getNewConnection () const |
Socket * | addConnection (int socket) |
const std::vector< Socket * > & | getClients () const |
There are two different modes:
Of course an object can switch between the states, in which case the previously created connections are closed and removed.
YGP::ConnectionMgr::ConnectionMgr | ( | ) |
Default constructor.
YGP::ConnectionMgr::~ConnectionMgr | ( | ) | [virtual] |
Destructor.
Socket * YGP::ConnectionMgr::addConnection | ( | int | socket | ) |
Adds a connection the the server connections.
NULL
) void YGP::ConnectionMgr::changeMode | ( | modeConnect | newMode | ) |
Changes the mode of the connection(s).
void YGP::ConnectionMgr::clearConnections | ( | ) |
Removes the available connections.
void YGP::ConnectionMgr::connectTo | ( | const char * | target, | |
unsigned int | port | |||
) | throw (YGP::CommError) |
Connect to server
on the specified port
.
target | Server to connect to | |
port | Port the server is listening at |
YGP::CommError | In case of a connection error |
void YGP::ConnectionMgr::connectTo | ( | const std::string & | server, | |
unsigned int | port | |||
) | throw (YGP::CommError) [inline] |
void YGP::ConnectionMgr::disconnect | ( | const Socket * | partner | ) |
Disconnects one of the partners.
partner | Partner to disconnect |
const std::vector<Socket*>& YGP::ConnectionMgr::getClients | ( | ) | const [inline] |
Returns the clients already connected to the server.
modeConnect YGP::ConnectionMgr::getMode | ( | ) | const [inline] |
Returns the actual mode of the connection.
int YGP::ConnectionMgr::getNewConnection | ( | ) | const |
Waits for a connection on the previously bound port.
Socket* YGP::ConnectionMgr::getSocket | ( | ) | const [inline] |
Returns the Socket over which to communicate (might be NULL).
void YGP::ConnectionMgr::listenAt | ( | unsigned int | port | ) | throw (YGP::CommError) |
Wait at port port
for connections.
port | Port the server is listening at |
YGP::CommError | In case of a connection error |