com.trolltech.qt.network
Class QNetworkProxy

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.network.QNetworkProxy
All Implemented Interfaces:
QtJambiInterface, java.lang.Cloneable

public class QNetworkProxy
extends QtJambiObject
implements java.lang.Cloneable

The QNetworkProxy class provides a network layer proxy. QNetworkProxy provides the method for configuring network layer proxy support to the Qt network classes. The currently supported classes are QAbstractSocket, QTcpSocket, QUdpSocket, QTcpServer, QHttp and QFtp. The proxy support is designed to be as transparent as possible. This means that existing network-enabled applications that you have written should automatically support network proxy using the following code.

The following code example is written in c++.

QNetworkProxy proxy;
proxy.setType(QNetworkProxy::Socks5Proxy);
proxy.setHostName("proxy.example.com");
proxy.setPort(1080);
proxy.setUser("username");
proxy.setPassword("password");
QNetworkProxy::setApplicationProxy(proxy);
An alternative to setting an application wide proxy is to specify the proxy for individual sockets using QAbstractSocket::setProxy() and QTcpServer::setProxy(). In this way, it is possible to disable the use of a proxy for specific sockets using the following code:

The following code example is written in c++.
serverSocket->setProxy(QNetworkProxy::NoProxy);
Network proxy is not used if the address used in connectToHost(), bind() or listen() is equivalent to QHostAddress::LocalHost or QHostAddress::LocalHostIPv6 .

Each type of proxy support has certain restrictions associated with it. You should read the ProxyType documentation carefully before selecting a proxy type to use.

Note: Changes made to currently connected sockets do not take effect. If you need to change a connected socket, you should reconnect it.

SOCKS5

The SOCKS5 support in Qt 4 is based on RFC 1928 and RFC 1929. The supported authentication methods are no authentication and username/password authentication. Both IPv4 and IPv6 are supported, but domain name resolution via the SOCKS server is not supported; i.e. all domain names are resolved locally. There are several things to remember when using SOCKS5 with QUdpSocket and QTcpServer:

With QUdpSocket, a call to bind() may fail with a timeout error. If a port number other than 0 is passed to bind(), it is not guaranteed that it is the specified port that will be used. Use localPort() and localAddress() to get the actual address and port number in use. Because proxied UDP goes through two UDP connections, it is more likely that packets will be dropped.

With QTcpServer a call to listen() may fail with a timeout error. If a port number other than 0 is passed to listen(), then it is not guaranteed that it is the specified port that will be used. Use serverPort() and serverAddress() to get the actual address and port used to listen for connections. SOCKS5 only supports one accepted connection per call to listen(), and each call is likely to result in a different serverPort() being used.

See also:
QAbstractSocket, and QTcpServer.


Nested Class Summary
static class QNetworkProxy.Capabilities
           
static class QNetworkProxy.Capability
          These flags indicate the capabilities that a given proxy server supports.
static class QNetworkProxy.ProxyType
          This enum describes the types of network proxying provided in Qt.
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QNetworkProxy()
          Constructs a QNetworkProxy with DefaultProxy type; the proxy type is determined by applicationProxy(), which defaults to NoProxy .
QNetworkProxy(QNetworkProxy.ProxyType type)
          Constructs a QNetworkProxy with type, hostName, port, user and password.
QNetworkProxy(QNetworkProxy.ProxyType type, java.lang.String host)
          Constructs a QNetworkProxy with type, hostName, port, user and password.
QNetworkProxy(QNetworkProxy.ProxyType type, java.lang.String host, int port)
          Constructs a QNetworkProxy with type, hostName, port, user and password.
QNetworkProxy(QNetworkProxy.ProxyType type, java.lang.String host, int port, java.lang.String username)
          Constructs a QNetworkProxy with type, hostName, port, user and password.
QNetworkProxy(QNetworkProxy.ProxyType type, java.lang.String host, int port, java.lang.String username, java.lang.String password)
          Constructs a QNetworkProxy with type, hostName, port, user and password.
QNetworkProxy(QNetworkProxy other)
          Constructs a copy of other.
 
Method Summary
static QNetworkProxy applicationProxy()
          Returns the application level network proxying.
 QNetworkProxy.Capabilities capabilities()
          Returns the capabilities of this proxy server.
 QNetworkProxy clone()
          This method is reimplemented for internal reasons
 java.lang.String hostName()
          Returns the host name of the proxy host.
 boolean isCachingProxy()
          Returns true if this proxy supports the QNetworkProxy::CachingCapability capability.
 boolean isTransparentProxy()
          Returns true if this proxy supports transparent tunneling of TCP connections.
 java.lang.String password()
          Returns the password used for authentication.
 int port()
          Returns the port of this proxy.
static void setApplicationProxy(QNetworkProxy proxy)
          Sets the application level network proxying to be networkProxy.
 void setCapabilities(QNetworkProxy.Capabilities capab)
          Sets the capabilities of this proxy to capabilities.
 void setCapabilities(QNetworkProxy.Capability[] capab)
          This is an overloaded method provided for convenience.
 void setHostName(java.lang.String hostName)
          Sets the host name of the proxy host to be hostName.
 void setPassword(java.lang.String password)
          Sets the password for proxy authentication to be password.
 void setPort(int port)
          Sets the port of the proxy host to be port.
 void setType(QNetworkProxy.ProxyType type)
          Sets the proxy type for this instance to be type.
 void setUser(java.lang.String userName)
          Sets the user name for proxy authentication to be user.
 QNetworkProxy.ProxyType type()
          Returns the proxy type for this instance.
 java.lang.String user()
          Returns the user name used for authentication.
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QNetworkProxy

public QNetworkProxy()
Constructs a QNetworkProxy with DefaultProxy type; the proxy type is determined by applicationProxy(), which defaults to NoProxy .

See also:
setType(), and setApplicationProxy().


QNetworkProxy

public QNetworkProxy(QNetworkProxy other)
Constructs a copy of other.


QNetworkProxy

public QNetworkProxy(QNetworkProxy.ProxyType type)
Constructs a QNetworkProxy with type, hostName, port, user and password.


QNetworkProxy

public QNetworkProxy(QNetworkProxy.ProxyType type,
                     java.lang.String host)
Constructs a QNetworkProxy with type, hostName, port, user and password.


QNetworkProxy

public QNetworkProxy(QNetworkProxy.ProxyType type,
                     java.lang.String host,
                     int port)
Constructs a QNetworkProxy with type, hostName, port, user and password.


QNetworkProxy

public QNetworkProxy(QNetworkProxy.ProxyType type,
                     java.lang.String host,
                     int port,
                     java.lang.String username)
Constructs a QNetworkProxy with type, hostName, port, user and password.


QNetworkProxy

public QNetworkProxy(QNetworkProxy.ProxyType type,
                     java.lang.String host,
                     int port,
                     java.lang.String username,
                     java.lang.String password)
Constructs a QNetworkProxy with type, hostName, port, user and password.

Method Detail

capabilities

public final QNetworkProxy.Capabilities capabilities()
Returns the capabilities of this proxy server.

See also:
setCapabilities(), and type().


hostName

public final java.lang.String hostName()
Returns the host name of the proxy host.

See also:
setHostName(), setPort(), and port().


isCachingProxy

public final boolean isCachingProxy()
Returns true if this proxy supports the QNetworkProxy::CachingCapability capability.

In Qt 4.4, the capability was tied to the proxy type, but since Qt 4.5 it is possible to remove the capability of caching from a proxy by calling setCapabilities().

See also:
capabilities(), type(), and isTransparentProxy().


isTransparentProxy

public final boolean isTransparentProxy()
Returns true if this proxy supports transparent tunneling of TCP connections. This matches the QNetworkProxy::TunnelingCapability capability.

In Qt 4.4, the capability was tied to the proxy type, but since Qt 4.5 it is possible to remove the capability of caching from a proxy by calling setCapabilities().

See also:
capabilities(), type(), and isCachingProxy().


password

public final java.lang.String password()
Returns the password used for authentication.

See also:
user(), setPassword(), and setUser().


setCapabilities

public final void setCapabilities(QNetworkProxy.Capability[] capab)
This is an overloaded method provided for convenience.


setCapabilities

public final void setCapabilities(QNetworkProxy.Capabilities capab)
Sets the capabilities of this proxy to capabilities.

See also:
setType(), and capabilities().


setHostName

public final void setHostName(java.lang.String hostName)
Sets the host name of the proxy host to be hostName.

See also:
hostName(), setPort(), and port().


setPassword

public final void setPassword(java.lang.String password)
Sets the password for proxy authentication to be password.

See also:
user(), setUser(), and password().


setType

public final void setType(QNetworkProxy.ProxyType type)
Sets the proxy type for this instance to be type.

Note that changing the type of a proxy does not change the set of capabilities this QNetworkProxy object holds.

See also:
type(), and setCapabilities().


setUser

public final void setUser(java.lang.String userName)
Sets the user name for proxy authentication to be user.

See also:
user(), setPassword(), and password().


type

public final QNetworkProxy.ProxyType type()
Returns the proxy type for this instance.

See also:
setType().


user

public final java.lang.String user()
Returns the user name used for authentication.

See also:
setUser(), setPassword(), and password().


applicationProxy

public static QNetworkProxy applicationProxy()
Returns the application level network proxying.

If a QAbstractSocket or QTcpSocket has the QNetworkProxy::DefaultProxy type, then the QNetworkProxy returned by this function is used.

See also:
QNetworkProxyFactory, setApplicationProxy(), QAbstractSocket::proxy(), and QTcpServer::proxy().


setApplicationProxy

public static void setApplicationProxy(QNetworkProxy proxy)
Sets the application level network proxying to be networkProxy.

If a QAbstractSocket or QTcpSocket has the QNetworkProxy::DefaultProxy type, then the QNetworkProxy set with this function is used. If you want more flexibility in determining which the proxy, use the QNetworkProxyFactory class.

Setting a default proxy value with this function will override the application proxy factory set with QNetworkProxyFactory::setApplicationProxyFactory.

See also:
QNetworkProxyFactory, applicationProxy(), QAbstractSocket::setProxy(), and QTcpServer::setProxy().


setPort

public final void setPort(int port)
Sets the port of the proxy host to be port.


port

public final int port()
Returns the port of this proxy.


clone

public QNetworkProxy clone()
This method is reimplemented for internal reasons

Overrides:
clone in class java.lang.Object