Linux based C++ class for easy communication via TCP sockets. More...
#include <tcpsocket.h>
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. | |
Linux based C++ class for easy communication via TCP sockets.
| TcpSocket::TcpSocket | ( | ) |
Constructor.
| 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");
| host_name | c string specify name of remote host | |
| host_port | integer value of remote port |
| void TcpSocket::disconnectFromHost | ( | ) |
Disconnecting from remote host.
This function will have effect only if socket is in ConnectedState.
| SocketError TcpSocket::error | ( | ) | const [inline] |
Get error state.
Error occures when state of socket is ErrorState.
| 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!
| buf | c string buffer for loading data | |
| buf_size | size of buffer |
| 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());
| data | c string containing data to send | |
| data_size | size of data to send |
| SocketState TcpSocket::state | ( | ) | const [inline] |
Get socket state.
1.6.3