Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

KSocket Class Reference

A TCP/IP client socket. More...

#include <ksock.h>

List of all members.

Public Slots

void slotWrite (int x)
void slotRead (int x)

Signals

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

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 enable)
void enableWrite (bool enable)


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.

Author:
Torben Weis <weis@uni-frankfurt.de>
Version:
Id:
ksock.h,v 1.53 2002/09/09 21:24:53 tjansen Exp

Definition at line 81 of file ksock.h.


Constructor & Destructor Documentation

KSocket::KSocket int    _sock
 

Constructs a KSocket with the provided file descriptor.

Parameters:
_sock  The file descriptor to use.

KSocket::KSocket const char *    _host,
unsigned short int    _port,
int    timeOut = 30
 

Creates a socket and connects 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::KSocket const char *    _path
 

Connects to a UNIX domain socket.

Parameters:
_path  The filename of the socket.

virtual KSocket::~KSocket   [virtual]
 

Destructor. Closes the socket if it is still open.


Member Function Documentation

void KSocket::closeEvent KSocket *    s [signal]
 

Raised when the connection is broken.

Parameters:
s  the KSocket that triggered the event

void KSocket::enableRead bool    enable
 

Enables 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.

Parameters:
enable  true to enable reading signals

void KSocket::enableWrite bool    enable
 

Enables 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 !

Parameters:
enable  true to enable writing signals

void KSocket::readEvent KSocket *    s [signal]
 

Data has arrived for reading.

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

Parameters:
s  the KSocket that triggered the event

void KSocket::slotRead int    x [slot]
 

Connected to the readNotifier.

Called when the socket is ready for reading.

Parameters:
x  ignored

void KSocket::slotWrite int    x [slot]
 

Connected to the writeNotifier.

Called when the socket is ready for writing.

Parameters:
x  ignored

int KSocket::socket   const [inline]
 

Returns a file descriptor for this socket.

Returns:
the file descriptor, or -1 when an error occured.

Definition at line 113 of file ksock.h.

void KSocket::writeEvent KSocket *    s [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 !

Parameters:
s  the KSocket that triggered the event


The documentation for this class was generated from the following file:
Generated on Wed Aug 13 23:30:24 2003 for kdelibs by doxygen1.2.18