# class KSocket | a TCP/IP client socket. More...
Definition | `#include <ksock.h>`
Inherits | QObject (qt) [public ]
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Methods

- KSocket ( int _sock )
- KSocket ( const char *_host, unsigned short int _port, int timeOut = 30)
- KSocket ( const char * _path )
- virtual ~KSocket ()
- int socket () const
- void enableRead ( bool )
- void enableWrite ( bool )
- unsigned long ipv4_addr ()

#### Public Slots

- void slotWrite ( int )
- void slotRead ( int )

#### Signals

- void readEvent ( KSocket * )
- void writeEvent ( KSocket * )
- void closeEvent ( KSocket * )

#### Public Static Methods

- static bool initSockaddr (ksockaddr_in *server_name, const char *hostname, unsigned short int port, int domain = PF_INET)

#### Protected Methods

- bool connect ( const QString& _host, unsigned short int _port )
- bool connect ( const char *_path )
- bool init_sockaddr ( const QString& hostname, unsigned short int port )

#### Protected Members

- ksockaddr_in server_name
- Forward unix_addr
- int sock
- int domain
- QSocketNotifier *readNotifier
- QSocketNotifier *writeNotifier

## Detailed Description

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 ) | ### KSocket

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) | ### KSocket

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 ) | ### KSocket

Connects to a UNIX domain socket.

Parameters:

_path | The filename of the socket.

~KSocket () | ### ~KSocket

[virtual]

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) | ### initSockaddr

[static]

A small wrapper around gethostbyname() and such.

int socket () | ### socket

[const]

Returns a file descriptor for this socket. Returns -1 when an error occured.

void enableRead ( bool ) | ### enableRead

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 ) | ### enableWrite

Enable the socket for writing.

If you enable write mode, the socket will emit the signal writeEvent() whenever the socket is ready for writing.

Warning: If you forget to call enableWrite(false) when you are not ready to send data, you will get lots of writeEvent() signals, in the order of thousands a second !

unsigned long ipv4_addr () | ### ipv4_addr

Return address.

void readEvent ( KSocket * ) | ### readEvent

[signal]

Data has arrived for reading.

This signal will only be raised if enableRead( `true` ) was called first.

void writeEvent ( KSocket * ) | ### writeEvent

[signal]

Socket is ready for writing.

This signal will only be raised if enableWrite( `true` ) was called first.

Warning: If you forget to call enableWrite(false) when you are not ready to send data, you will get lots of writeEvent() signals, in the order of thousands a second !

void closeEvent ( KSocket * ) | ### closeEvent

[signal]

Raised when the connection is broken.

void slotWrite ( int ) | ### slotWrite

[slot]

Connected to the writeNotifier.

Called when the socket is ready for writing.

void slotRead ( int ) | ### slotRead

[slot]

Connected to the readNotifier.

Called when the socket is ready for reading.

bool connect ( const QString& _host, unsigned short int _port ) | ### connect

[protected]

Reimplemented from QObject.

bool connect ( const char *_path ) | ### connect

[protected]

Reimplemented from QObject.

bool init_sockaddr ( const QString& hostname, unsigned short int port ) | ### init_sockaddr

[protected]

ksockaddr_in server_name | ### server_name

[protected]

int sock | ### sock

[protected]

int domain | ### domain

[protected]

QSocketNotifier * readNotifier | ### readNotifier

[protected]

QSocketNotifier * writeNotifier | ### writeNotifier

[protected]

- Version: $Id: ksock.h,v 1.42 2000/12/18 01:09:22 waba Exp $
- Author: Torben Weis <weis@uni-frankfurt.de>
- Generated: root@i386.ports.openbsd.org on Wed Apr 25 13:58:13 2001, using kdoc 2.0a53.