#include <Connection.h>
Public Member Functions | |
Connection () | |
Connection (const char *hostname, int port, int iSize) | |
~Connection () | |
bool | connect (const char *host, int port) |
void | disconnect (void) |
bool | isConnected (void) const |
int | message_loop (FILE *in, FILE *out) |
int | receiveMessage (char *msg, int maxsize) |
bool | sendMessage (const char *msg) |
void | show (ostream os) |
Private Attributes | |
Socket | m_sock |
int | m_iMaxMsgSize |
Definition at line 75 of file Connection.h.
Connection::Connection | ( | ) |
Default constructor. Only sets the maximum message size.
Definition at line 72 of file Connection.cpp.
References m_iMaxMsgSize.
Connection::Connection | ( | const char * | hostname, | |
int | port, | |||
int | iMaxSize | |||
) |
Constructor makes a connection with the server using the connect method.
hostname | string representation of host machine (string or IP number) | |
port | port number for connection of the host machine | |
iMaxSize | maximum message size that can be sent or received |
Definition at line 81 of file Connection.cpp.
References connect(), Logger::log(), Log, and m_iMaxMsgSize.
Connection::~Connection | ( | ) |
Deconstructor closes the connection with the server
Definition at line 93 of file Connection.cpp.
References disconnect().
bool Connection::connect | ( | const char * | host, | |
int | port | |||
) |
This method sets up a connection with the server.
hostname | string representation of host machine (string or IP number) | |
port | port number for connection of the host machine |
Definition at line 102 of file Connection.cpp.
References m_sock, _socket::serv_addr, and _socket::socketfd.
Referenced by Connection().
void Connection::disconnect | ( | void | ) |
This method closes the current socket connection.
Definition at line 184 of file Connection.cpp.
References isConnected(), m_sock, and _socket::socketfd.
Referenced by main(), and ~Connection().
bool Connection::isConnected | ( | void | ) | const |
This method determines whether the socket connection is connected.
Definition at line 199 of file Connection.cpp.
References m_sock, and _socket::socketfd.
Referenced by disconnect(), and show().
int Connection::message_loop | ( | FILE * | fpin, | |
FILE * | fpout | |||
) |
This method always loops and waits for input. When input is received from fpin then this input is send to the server using the current connection. When message is received from the server, this message is sent to fpout.
fpin | file pointer from which input is read (i.e. stdin ) | |
fpout | file pointer to which output should be directed (i.e. stdout) |
Definition at line 271 of file Connection.cpp.
References m_iMaxMsgSize, m_sock, receiveMessage(), sendMessage(), and _socket::socketfd.
int Connection::receiveMessage | ( | char * | msg, | |
int | maxsize | |||
) |
This method reads a message from the connection. When there is no message available, it blocks till it receives a message.
msg | string in which message is stored | |
maxsize | maximum size of the message. |
Definition at line 209 of file Connection.cpp.
References m_sock, _socket::serv_addr, and _socket::socketfd.
Referenced by SenseHandler::handleMessagesFromServer(), and message_loop().
bool Connection::sendMessage | ( | const char * | msg | ) |
This method sends a message to the server using the current connection.
msg | string which contains message |
Definition at line 253 of file Connection.cpp.
References m_sock, _socket::serv_addr, and _socket::socketfd.
Referenced by message_loop(), ActHandler::sendCommands(), ActHandler::sendMessage(), and ActHandler::sendMessageDirect().
void Connection::show | ( | ostream | os | ) |
This method prints whether the connection is up or not.
os | output stream to which output should be directed |
Definition at line 321 of file Connection.cpp.
References isConnected().
Socket Connection::m_sock [private] |
communication protocol with the server.
Definition at line 77 of file Connection.h.
Referenced by connect(), disconnect(), isConnected(), message_loop(), receiveMessage(), and sendMessage().
int Connection::m_iMaxMsgSize [private] |
max message size for send and receive
Definition at line 78 of file Connection.h.
Referenced by Connection(), and message_loop().