|
|
A TCP/IP client socket.
You can connect this socket to any Internet address.
The socket gives you three signals: When ready for reading, ready for writing or if the connection is broken. Using socket() you get a file descriptor which you can use with the usual UNIX function like write(..) or read(...). If you have already such a socket identifier you can construct a KSocket on this identifier.
If socket() delivers a value of -1 or less, the connection was not successful.
KSocket ( int _sock ) |
Create a KSocket with the provided file descriptor.
Parameters:
_sock | The file descriptor to use. |
KSocket ( const char *_host, unsigned short int _port, int timeOut = 30) |
Create a socket and connect to a host.
Parameters:
_host | The remote host to which to connect. |
_port | The port on the remote host. |
timeOut | The number of seconds waiting for connect (default 30). |
KSocket ( const char * _path ) |
Connects to a UNIX domain socket.
Parameters:
_path | The filename of the socket. |
~KSocket () |
Destructor. Closes the socket if it is still open.
bool initSockaddr (ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET) |
A small wrapper around gethostbyname() and such.
int socket () |
Returns a file descriptor for this socket.
void enableRead ( bool ) |
Enable the socket for reading.
If you enable read mode, the socket will emit the signal readEvent() whenever there is something to read out of this socket.
void enableWrite ( bool ) |
Enable the socket for writing.
If you enable write mode, the socket will emit the signal writeEvent() whenever the socket is ready for writing.
unsigned long ipv4_addr () |
Return address.
void readEvent ( KSocket * ) |
Data has arrived for reading.
This signal will only be raised if enableRead( true
) was called
first.
void writeEvent ( KSocket * ) |
Socket is ready for writing.
This signal will only be raised if enableWrite( true
) was
called first.
void closeEvent ( KSocket * ) |
Raised when the connection is broken.
void slotWrite ( int ) |
Connected to the writeNotifier.
Called when the socket is ready for writing.
void slotRead ( int ) |
Connected to the readNotifier.
Called when the socket is ready for reading.
int sock |
The file descriptor for this socket. sock may be -1. This indicates that it is not connected.