Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Connection Class Reference

#include <Connection.h>

Collaboration diagram for Connection:

Collaboration graph
[legend]
List of all members.

Public Methods

 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

Detailed Description

This class creates creates a (socket) connection using a hostname and a port number. After the connection is created it is possible to send and receive messages from this connection. It is based on the client program supplied with the soccer server defined in client.c and created by Istuki Noda et al.

Definition at line 75 of file Connection.h.


Constructor & Destructor Documentation

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.

Parameters:
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(), and m_iMaxMsgSize.

Connection::~Connection  
 

Deconstructor closes the connection with the server

Definition at line 93 of file Connection.cpp.

References disconnect().


Member Function Documentation

bool Connection::connect const char *    host,
int    port
 

This method sets up a connection with the server.

Parameters:
hostname  string representation of host machine (string or IP number)
port  port number for connection of the host machine
Returns:
bool indicating whether connection was made

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.

Returns:
bool indicating whether socket connection is available

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.

Parameters:
fpin  file pointer from which input is read (i.e. stdin )
fpout  file pointer to which output should be directed (i.e. stdout)
Returns:
0 but only when error occured in reading input

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.

Parameters:
msg  string in which message is stored
maxsize  maximum size of the message.
Returns:
-1: error, 0: 0 bytes were read, 1 when read was succesfull

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.

Parameters:
msg  string which contains message
Returns:
true on succes, false in case of failure

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.

Parameters:
os  output stream to which output should be directed

Definition at line 321 of file Connection.cpp.

References isConnected().


Member Data Documentation

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().

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().


The documentation for this class was generated from the following files:
Generated on Fri Nov 7 11:46:01 2003 for UvA Trilearn 2003 Base Code by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001