TcpSocket Class Reference

Linux based C++ class for easy communication via TCP sockets. More...

#include <tcpsocket.h>

List of all members.

Public Types

enum  SocketError {
  UnknownError, SocketAccessError, UnknownHostError, SocketCreatingError,
  ConnectingError, SocketDataSendError, SocketDataReadError
}
 

Error list of TcpSocket class.

More...
enum  SocketState { UnconnectedState, ConnectingState, ConnectedState, ErrorState }
 

TcpSocket state list.

More...

Public Member Functions

 TcpSocket ()
 Constructor.
bool connectToHost (char *host_name, int host_port)
 Connecting to remote host.
void disconnectFromHost ()
 Disconnecting from remote host.
int sendData (char *data, int data_size)
 Send data to host.
int readData (char *buf, int buf_size)
 Read recieved data from host.
SocketError error () const
 Get error state.
SocketState state () const
 Get socket state.

Detailed Description

Linux based C++ class for easy communication via TCP sockets.


Member Enumeration Documentation

Error list of TcpSocket class.

Actual error can be reached via function error().

See also:
error()
Enumerator:
UnknownError 
SocketAccessError 
UnknownHostError 
SocketCreatingError 
ConnectingError 
SocketDataSendError 
SocketDataReadError 

TcpSocket state list.

Actual socket state can be reached via function state().

See also:
state()
Enumerator:
UnconnectedState 
ConnectingState 
ConnectedState 
ErrorState 

Constructor & Destructor Documentation

TcpSocket::TcpSocket (  ) 

Constructor.


Member Function Documentation

bool TcpSocket::connectToHost ( char *  host_name,
int  host_port 
)

Connecting to remote host.

With this function you can connect to remote server.

Example: if ( connectToHost("127.0.0.1",4321) ) printf("Connected\n");

Parameters:
host_name c string specify name of remote host
host_port integer value of remote port
Returns:
result of connecting (true on success)
void TcpSocket::disconnectFromHost (  ) 

Disconnecting from remote host.

This function will have effect only if socket is in ConnectedState.

See also:
state()
SocketError TcpSocket::error (  )  const [inline]

Get error state.

Error occures when state of socket is ErrorState.

Returns:
error state
See also:
state()
int TcpSocket::readData ( char *  buf,
int  buf_size 
)

Read recieved data from host.

Function provide reading data sended by remote host. Be careful with manipulating buffer memory!

Parameters:
buf c string buffer for loading data
buf_size size of buffer
Returns:
size of successly readed data (-1 on error)
int TcpSocket::sendData ( char *  data,
int  data_size 
)

Send data to host.

Function provide data sending to remote host.

Example:
char * data = "Hello\n";
if ( sendData(data,strlen(data)) == -1 ) printf("Error while sending data: %s\n",error());

Parameters:
data c string containing data to send
data_size size of data to send
Returns:
size of successly sended data (-1 on error)
SocketState TcpSocket::state (  )  const [inline]

Get socket state.

Returns:
socket state

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Enumerations Enumerator Friends
Generated on Sun Jan 23 19:51:23 2011 for Peltast by  doxygen 1.6.3