KDE 4.9 PyKDE API Reference

- KDE's Python API

# KSocketFactory Namespace Reference

`from PyKDE4.kdecore.KSocketFactory import *`

## Detailed Description

KSocketFactory provides functions for opening sockets to remote hosts

KSocketFactory is a socket-opener group of functions that must be used whenever a KDE application wants to communicate with a remote host. It will determine the necessary proxy and local KDE settings, then open the connection. The typical use-case is:

    d->socket = KSocketFactory.connectToHost("www.kde.org", "http");
    d->socket->setParent(this);
    QObject.connect(d->socket, SIGNAL(connected()),
    this, SLOT(socketConnected()));

Synchronous operation is not recommended, since it may lead to UI deadlocks. It is preferred to return to the mainloop if the socket is being created in the main GUI thread.

However, if the socket is created in an auxiliary thread, it is possible to use something equivalent to synchronous mode:

    d->socket = KSocketFactory.synchronousConnectToHost("www.kde.org", "http");
    d->socket->setParent(this);

All objects returned from these functions belong to the caller and must be disposed of properly. Calling QObject.setParent() or passing a parent object is the recommended way.

Author:
  Thiago Macieira <thiago@kde.org>

## Functions
QTcpSocket | connectToHost (QString protocol, QString host, int port, QObject parent=0)
QTcpSocket | connectToHost (QUrl url, QObject parent=0)
| connectToHost (QTcpSocket socket, QString protocol, QString host, int port)
| connectToHost (QTcpSocket socket, QUrl url)
QUdpSocket | datagramSocket (QString protocol, QString host, QObject parent=0)
QTcpServer | listen (QString protocol, QHostAddress address=QHostAddress.Any, int port=0, QObject parent=0)
QNetworkProxy | proxyForConnection (QString protocol, QString host)
QNetworkProxy | proxyForDatagram (QString protocol, QString host)
QNetworkProxy | proxyForListening (QString protocol)
QTcpSocket | synchronousConnectToHost (QString protocol, QString host, int port, int msecs=30000, QObject parent=0)
QTcpSocket | synchronousConnectToHost (QUrl url, int msecs=30000, QObject parent=0)
| synchronousConnectToHost (QTcpSocket socket, QString protocol, QString host, int port, int msecs=30000)
| synchronousConnectToHost (QTcpSocket socket, QUrl url, int msecs=30000)

## Function Documentation

QTcpSocket connectToHost | ( | QString | protocol,
|  | QString | host,
|  | int | port,
|  | QObject | parent=0
| ) |  |  |

QTcpSocket connectToHost | ( | QUrl | url,
|  | QObject | parent=0
| ) |  |  |

connectToHost | ( | QTcpSocket | socket,
|  | QString | protocol,
|  | QString | host,
|  | int | port
| ) |  |  |

connectToHost | ( | QTcpSocket | socket,
|  | QUrl | url
| ) |  |  |

QUdpSocket datagramSocket | ( | QString | protocol,
|  | QString | host,
|  | QObject | parent=0
| ) |  |  |

QTcpServer listen | ( | QString | protocol,
|  | QHostAddress | address=QHostAddress.Any,
|  | int | port=0,
|  | QObject | parent=0
| ) |  |  |

Opens a TCP/IP socket for listening protocol protocol, binding only at address address. The port parameter indicates the port to be opened.

This function does not return 0. If the opening of the socket failed for some reason, it will return a QTcpServer object that is not listening (QTcpServer.isListening() returns false), with a properly set error string indicating the reason).

Note that passing 0 as the default port number will cause the operating system to automatically allocate a free port for the socket.

Parameters:

  | protocol | the protocol this socket will accept
  | address | the address to listen at
  | port | the default port for the service
  | parent | the parent object to be passed to the QTcpServer constructor

QNetworkProxy proxyForConnection | ( | QString | protocol,
|  | QString | host
| ) |  |  |

QNetworkProxy proxyForDatagram | ( | QString | protocol,
|  | QString | host
| ) |  |  |

QNetworkProxy proxyForListening | ( | QString | protocol
| ) |  |  |

QTcpSocket synchronousConnectToHost | ( | QString | protocol,
|  | QString | host,
|  | int | port,
|  | int | msecs=30000,
|  | QObject | parent=0
| ) |  |  |

QTcpSocket synchronousConnectToHost | ( | QUrl | url,
|  | int | msecs=30000,
|  | QObject | parent=0
| ) |  |  |

synchronousConnectToHost | ( | QTcpSocket | socket,
|  | QString | protocol,
|  | QString | host,
|  | int | port,
|  | int | msecs=30000
| ) |  |  |

synchronousConnectToHost | ( | QTcpSocket | socket,
|  | QUrl | url,
|  | int | msecs=30000
| ) |  |  |