1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \group network
|
---|
44 | \title Network Programming API
|
---|
45 | \brief Classes for Network Programming
|
---|
46 |
|
---|
47 | \ingroup groups
|
---|
48 | */
|
---|
49 |
|
---|
50 | /*!
|
---|
51 | \page network-programming.html
|
---|
52 | \title Network Programming
|
---|
53 | \brief An Introduction to Network Programming with Qt
|
---|
54 |
|
---|
55 | The QtNetwork module offers classes that allow you to write TCP/IP clients
|
---|
56 | and servers. it offers classes such as QFtp that implement specific
|
---|
57 | application-level protocols, lower-level classes such as QTcpSocket,
|
---|
58 | QTcpServer and QUdpSocket that represent low level network concepts,
|
---|
59 | and high level classes such as QNetworkRequest, QNetworkReply and
|
---|
60 | QNetworkAccessManager to perform network operations using common protocols.
|
---|
61 |
|
---|
62 | \tableofcontents
|
---|
63 |
|
---|
64 | \section1 Qt's Classes for Network Programming
|
---|
65 |
|
---|
66 | The following classes provide support for network programming in Qt.
|
---|
67 |
|
---|
68 | \annotatedlist network
|
---|
69 |
|
---|
70 | \section1 High Level Network Operations for HTTP and FTP
|
---|
71 |
|
---|
72 | The Network Access API is a collection of classes for performing
|
---|
73 | common network operations. The API provides an abstraction layer
|
---|
74 | over the specific operations and protocols used (for example,
|
---|
75 | getting and posting data over HTTP), and only exposes classes,
|
---|
76 | functions, and signals for general or high level concepts.
|
---|
77 |
|
---|
78 | Network requests are represented by the QNetworkRequest class,
|
---|
79 | which also acts as a general container for information associated
|
---|
80 | with a request, such as any header information and the encryption
|
---|
81 | used. The URL specified when a request object is constructed
|
---|
82 | determines the protocol used for a request.
|
---|
83 | Currently HTTP, FTP and local file URLs are supported for uploading
|
---|
84 | and downloading.
|
---|
85 |
|
---|
86 | The coordination of network operations is performed by the
|
---|
87 | QNetworkAccessManager class. Once a request has been created,
|
---|
88 | this class is used to dispatch it and emit signals to report on
|
---|
89 | its progress. The manager also coordinates the use of
|
---|
90 | \l{QNetworkCookieJar}{cookies} to store data on the client,
|
---|
91 | authentication requests, and the use of proxies.
|
---|
92 |
|
---|
93 | Replies to network requests are represented by the QNetworkReply
|
---|
94 | class; these are created by QNetworkAccessManager when a request
|
---|
95 | is dispatched. The signals provided by QNetworkReply can be used
|
---|
96 | to monitor each reply individually, or developers may choose to
|
---|
97 | use the manager's signals for this purpose instead and discard
|
---|
98 | references to replies. Since QNetworkReply is a subclass of
|
---|
99 | QIODevice, replies can be handled synchronously or asynchronously;
|
---|
100 | i.e., as blocking or non-blocking operations.
|
---|
101 |
|
---|
102 | Each application or library can create one or more instances of
|
---|
103 | QNetworkAccessManager to handle network communication.
|
---|
104 |
|
---|
105 | \section1 Writing FTP Clients with QFtp
|
---|
106 |
|
---|
107 | FTP (File Transfer Protocol) is a protocol used almost exclusively
|
---|
108 | for browsing remote directories and for transferring files.
|
---|
109 |
|
---|
110 | \image httpstack.png FTP Client and Server
|
---|
111 |
|
---|
112 | FTP uses two network connections, one for sending
|
---|
113 | commands and one for transferring data. The
|
---|
114 | FTP protocol has a state and requires the client to send several
|
---|
115 | commands before a file transfer takes place.
|
---|
116 | FTP clients establish a connection
|
---|
117 | and keeps it open throughout the session. In each session, multiple
|
---|
118 | transfers can occur.
|
---|
119 |
|
---|
120 | The QFtp class provides client-side support for FTP.
|
---|
121 | It has the following characteristics:
|
---|
122 | \list
|
---|
123 |
|
---|
124 | \o \e{Non-blocking behavior.} QFtp is asynchronous.
|
---|
125 | You can schedule a series of commands which are executed later,
|
---|
126 | when control returns to Qt's event loop.
|
---|
127 |
|
---|
128 | \o \e{Command IDs.} Each command has a unique ID number that you
|
---|
129 | can use to follow the execution of the command. For example, QFtp
|
---|
130 | emits the \l{QFtp::commandStarted()}{commandStarted()} and
|
---|
131 | \l{QFtp::commandFinished()}{commandFinished()} signal with the
|
---|
132 | command ID for each command that is executed.
|
---|
133 |
|
---|
134 | \o \e{Data transfer progress indicators.} QFtp emits signals
|
---|
135 | whenever data is transferred (QFtp::dataTransferProgress(),
|
---|
136 | QNetworkReply::downloadProgress(), and
|
---|
137 | QNetworkReply::uploadProgress()). You could connect these signals
|
---|
138 | to QProgressBar::setProgress() or QProgressDialog::setProgress(),
|
---|
139 | for example.
|
---|
140 |
|
---|
141 | \o \e{QIODevice support.} The class supports convenient
|
---|
|
---|