|
|
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 |
Constructs 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 |
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 ( 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.
int socket ()
| socket |
[const]
Returns a file descriptor for this socket.
Returns: the file descriptor, or -1 when an error occured.
void enableRead ( bool enable )
| enableRead |
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 enableWrite ( bool enable )
| enableWrite |
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 |
unsigned long ipv4_addr ()
| ipv4_addr |
Return address. This function is dumb. Don't ever use it if you need the peer address of this socket, use KExtendedSocket::peerAddress(int) instead
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. Don't use this in new programs. Use KExtendedSocket::lookup
void readEvent ( KSocket *s )
| readEvent |
[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 writeEvent ( KSocket *s )
| 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 !
Parameters:
s | the KSocket that triggered the event |
void closeEvent ( KSocket *s )
| closeEvent |
[signal]
Raised when the connection is broken.
Parameters:
s | the KSocket that triggered the event |
void slotWrite ( int x)
| slotWrite |
[slot]
Connected to the writeNotifier.
Called when the socket is ready for writing.
Parameters:
x | ignored |
void slotRead ( int x )
| slotRead |
[slot]
Connected to the readNotifier.
Called when the socket is ready for reading.
Parameters:
x | ignored |
bool connect ( const QString& _host, unsigned short int _port, int timeout = 0 )
| connect |
[protected]
bool connect ( const char *_path )
| connect |
[protected]
int sock | sock |
[protected]