• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

Functions
KSocketFactory Namespace Reference

Functions

QTcpSocket * connectToHost (const QString &protocol, const QString &host, quint16 port, QObject *parent=0)
 
QTcpSocket * connectToHost (const QUrl &url, QObject *parent=0)
 
void connectToHost (QTcpSocket *socket, const QString &protocol, const QString &host, quint16 port)
 
void connectToHost (QTcpSocket *socket, const QUrl &url)
 
QUdpSocket * datagramSocket (const QString &protocol, const QString &host, QObject *parent=0)
 
QTcpServer * listen (const QString &protocol, const QHostAddress &address=QHostAddress::Any, quint16 port=0, QObject *parent=0)
 
QNetworkProxy proxyForConnection (const QString &protocol, const QString &host)
 
QNetworkProxy proxyForDatagram (const QString &protocol, const QString &host)
 
QNetworkProxy proxyForListening (const QString &protocol)
 
QTcpSocket * synchronousConnectToHost (const QString &protocol, const QString &host, quint16 port, int msecs=30000, QObject *parent=0)
 
QTcpSocket * synchronousConnectToHost (const QUrl &url, int msecs=30000, QObject *parent=0)
 
void synchronousConnectToHost (QTcpSocket *socket, const QString &protocol, const QString &host, quint16 port, int msecs=30000)
 
void synchronousConnectToHost (QTcpSocket *socket, const QUrl &url, int msecs=30000)
 

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 thiag.nosp@m.o@kd.nosp@m.e.org

Function Documentation

QTcpSocket * KSocketFactory::connectToHost ( const QString &  protocol,
const QString &  host,
quint16  port,
QObject *  parent = 0 
)

Initiates a TCP/IP socket connection to remote node (host) host, using the protocol.

Returns a QTcpSocket that is connecting (i.e., in a state before QAbstractSocket::Connected) in most cases, even if the target service doesn't exist or if a connection failure happens.

This function never returns 0. If the returned socket cannot connect, it will emit the QAbstractSocket::error() signal. Otherwise, the QAbstractSocket::connected() signal will be emitted eventually.

The protocol parameter must be a string representation of the protocol being attempted, like "http", "ftp" or "xmpp". It might be used to determine the proxy type – for instance, the proxy for HTTP connections might be different from the proxy for other connections. Pass an empty QString if the connection is of no established protocol.

The port parameter can be used to specify the port number lookup if the service is not a well-known service.

Parameters
protocolthe protocol this socket will use
hostthe remote node (host) to connect to
portthe port number to connect to
parentthe parent object to be passed to the QTcpSocket constructor
Threadsafe:

Definition at line 69 of file ksocketfactory.cpp.

QTcpSocket * KSocketFactory::connectToHost ( const QUrl &  url,
QObject *  parent = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 78 of file ksocketfactory.cpp.

void KSocketFactory::connectToHost ( QTcpSocket *  socket,
const QString &  protocol,
const QString &  host,
quint16  port 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 52 of file ksocketfactory.cpp.

void KSocketFactory::connectToHost ( QTcpSocket *  socket,
const QUrl &  url 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 64 of file ksocketfactory.cpp.

QUdpSocket * KSocketFactory::datagramSocket ( const QString &  protocol,
const QString &  host,
QObject *  parent = 0 
)

Definition at line 126 of file ksocketfactory.cpp.

QTcpServer * KSocketFactory::listen ( const QString &  protocol,
const QHostAddress &  address = QHostAddress::Any,
quint16  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
protocolthe protocol this socket will accept
addressthe address to listen at
portthe default port for the service
parentthe parent object to be passed to the QTcpServer constructor

Definition at line 115 of file ksocketfactory.cpp.

QNetworkProxy KSocketFactory::proxyForConnection ( const QString &  protocol,
const QString &  host 
)

Definition at line 137 of file ksocketfactory.cpp.

QNetworkProxy KSocketFactory::proxyForDatagram ( const QString &  protocol,
const QString &  host 
)

Definition at line 147 of file ksocketfactory.cpp.

QNetworkProxy KSocketFactory::proxyForListening ( const QString &  protocol)

Definition at line 142 of file ksocketfactory.cpp.

QTcpSocket * KSocketFactory::synchronousConnectToHost ( const QString &  protocol,
const QString &  host,
quint16  port,
int  msecs = 30000,
QObject *  parent = 0 
)

This function behaves exactly like connectToHost() above, except that the socket it returns is either in QAbstractSocket::Connected state, or it has failed connecting altogether.

This function should be used if a synchronous connection is necessary instead of calling QAbstractSocket::waitForConnected(), since that may not work on all objects returned from connectToHost().

This function does not return 0. If the connection attempt failed for some reason, the socket state will be QAbstractSocket::UnconnectedState and QAbstractSocket::isValid will return false. The socket error state and string will contain more information.

Warning
: This function may block.
Parameters
protocolthe protocol this socket will use
hostthe remote node (host) to connect to
portthe port number to connect to
msecsthe time (in milliseconds) to wait while attempting to connect
parentthe parent object to be passed to the QTcpSocket constructor
Threadsafe:

Definition at line 100 of file ksocketfactory.cpp.

QTcpSocket * KSocketFactory::synchronousConnectToHost ( const QUrl &  url,
int  msecs = 30000,
QObject *  parent = 0 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 110 of file ksocketfactory.cpp.

void KSocketFactory::synchronousConnectToHost ( QTcpSocket *  socket,
const QString &  protocol,
const QString &  host,
quint16  port,
int  msecs = 30000 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 83 of file ksocketfactory.cpp.

void KSocketFactory::synchronousConnectToHost ( QTcpSocket *  socket,
const QUrl &  url,
int  msecs = 30000 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 95 of file ksocketfactory.cpp.

This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:14 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal