void Client::sessionOpened() { // Save the used configuration QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); enableSendButton(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QNetworkConfigurationManager manager; if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { // Get saved network configuration QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); settings.endGroup(); // If the saved network configuration is not currently discovered use the system default QNetworkConfiguration config = manager.configurationFromIdentifier(id); if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { config = manager.defaultConfiguration(); } QNetworkSession *networkSession = new QNetworkSession(config, &app); networkSession->open(); networkSession->waitForOpened(); if (networkSession->isOpen()) { // Save the used configuration QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) { id = networkSession->sessionProperty( QLatin1String("UserChoiceConfiguration")).toString(); } else { id = config.identifier(); } QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } } //ChatDialog dialog; InitialWindow window; #ifdef Q_OS_SYMBIAN // Make application better looking and more usable on small screen // dialog.showMaximized(); #else // dialog.show(); window.show(); #endif return app.exec(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QNetworkConfigurationManager manager; if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { // Get saved network configuration QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); settings.endGroup(); // If the saved network configuration is not currently discovered use the system default QNetworkConfiguration config = manager.configurationFromIdentifier(id); if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { config = manager.defaultConfiguration(); } QNetworkSession *networkSession = new QNetworkSession(config, &a); networkSession->open(); networkSession->waitForOpened(); if (networkSession->isOpen()) { // Save the used configuration QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) { id = networkSession->sessionProperty( QLatin1String("UserChoiceConfiguration")).toString(); } else { id = config.identifier(); } QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } } interface w; w.show(); return a.exec(); }
void Client::sessionOpened() { // Save the used configuration QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); }
void Client::sessionOpened() { QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); statusLabel->setText(tr("<FILLIN>")); }
void Ftp::enableConnect() { // Save the used configuration QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); qDebug() << "FTP: Connection opened"; connected = networkSession->isOpen(); }
void Server::sessionOpened() { // Save the used configuration if (networkSession) { QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } tcpServer = new QTcpServer(this); if (tcpServer) { if (!tcpServer->listen()) { TRACE_ERROR(NET, "Unable to start the server: %s\n", tcpServer->errorString().toStdString().c_str()); return; } } QString ipAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // use the first non-localhost IPv4 address for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { ipAddress = ipAddressesList.at(i).toString(); break; } } // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); //TRACE_INFO(NET, "The server is running on: %s @ %i\n", ipAddress.toStdString().c_str(), tcpServer->serverPort()); }
void Server::sessionOpened() { // Save the used configuration if (networkSession) { QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } tcpServer = new QTcpServer(this); if (!tcpServer->listen()) { // QMessageBox::critical(this, tr("Fortune Server"), // tr("Unable to start the server: %1.") // .arg(tcpServer->errorString())); std::cout << "Unable to start the server." <<std::endl; //close(); return; } QString ipAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // use the first non-localhost IPv4 address for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { ipAddress = ipAddressesList.at(i).toString(); break; } } // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); // statusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n" // "Run the Fortune Client example now.") // .arg(ipAddress).arg(tcpServer->serverPort())); std::cout << "The server is running on IP: "<<ipAddress.toStdString()<<std::endl; std::cout <<"port: " << tcpServer->serverPort() << std::endl; std::cout <<"Run the Fortune Client example now." <<std::endl; }
void Server::sessionOpened() { // Save the used configuration if (networkSession) { QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } tcpServer = new QTcpServer(this); //if (!tcpServer->listen()) { // return; //} if (!tcpServer->listen(QHostAddress::Any, 54321)) { return; } QString ipAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // use the first non-localhost IPv4 address for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { ipAddress = ipAddressesList.at(i).toString(); break; } } // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); QTextStream out(stdout); out << tr("The server is running on\n\nIP: %1\nport: %2\n\n" "Run the Fortune Client example now.\n") .arg(ipAddress).arg(tcpServer->serverPort()); }
void FtpWindow::enableConnectButton() { // Save the used configuration QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); connectButton->setEnabled(true); statusLabel->setText(tr("Please enter the name of an FTP server.")); }
void MainWindow::sessionOpened() { //saves any settings needed if(networkSession){ QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else{ id=config.identifier();} QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } //in case problem starting server. hotelServer = new QTcpServer(this); if(!hotelServer->listen()) { QMessageBox::critical(this, tr("Fortune Server"), tr("Unable to start the server: %1.") .arg(hotelServer->errorString())); close(); return; } //for user readability, ipaddress is labeled QString ipAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { ipAddress = ipAddressesList.at(i).toString(); break; } } if (ipAddress.isEmpty()){ ipAddress = QHostAddress(QHostAddress::LocalHost).toString();} ui->statusLabel->setText("Server is now running. Please open client application."); ui->IPLabel->setText(tr("ServerIP: %1").arg(ipAddress)); ui->portLabel->setText(tr("Port: %1").arg(hotelServer->serverPort())); }
void Server::sessionOpened() { // Save the used configuration if (m_network_session) { QNetworkConfiguration config = m_network_session->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = m_network_session->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } m_tcp_server = new QTcpServer(this); if (!m_tcp_server->listen(QHostAddress::Any, 3422)) { QMessageBox::critical(this, tr("Messenger Server"), tr("Unable to start the server: %1.") .arg(m_tcp_server->errorString())); close(); return; } QString ipAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // use the first non-localhost IPv4 address for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { ipAddress = ipAddressesList.at(i).toString(); break; } } // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); m_status_label->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n" "Waiting for clients to connect...") .arg(ipAddress).arg(m_tcp_server->serverPort())); }
void Server::sessionOpen() { emit write_message(tr("Network session opened.")); // Save the used configuration if (networkSession) { QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } if (!tcpServer) tcpServer = new QTcpServer(this); if (!tcpServer->listen(QHostAddress::Any, local_port)) { emit error(tr("Unable to start the server: %1.").arg(tcpServer->errorString())); return; } QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // use the first non-localhost IPv4 address for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { thisIPAddress = ipAddressesList.at(i).toString(); break; } } // if we did not find one, use IPv4 localhost if (thisIPAddress.isEmpty()) thisIPAddress = QHostAddress(QHostAddress::LocalHost).toString(); emit write_message(tr("The server is running on IP: %1 port: %2\n").arg(thisIPAddress).arg(tcpServer->serverPort())); connectionTimeout(); }
void S2Controller::sessionOpened() { // Save the used configuration QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); statusLabel->setText(tr("Prototype Controller requires " "PrairieView to run at the same time.")); enablesendCommandButton(); }
void Client::sessionOpened() { // Save the used configuration QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); statusLabel->setText(tr("This examples requires that you run the " "Fortune Server example as well.")); enableGetFortuneButton(); }
void FtpDownloader::enableConnectButton() { // Save the used configuration QNetworkConfiguration config = m_networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = m_networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); // Update the status properties m_connectPossible = true; emit connectPossibleChanged(); m_statusText = tr("Please enter the name of an FTP server."); emit statusTextChanged(); }
void Server::sessionOpened() { // Save the used configuration if (networkSession) { QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } tcpServer = new QTcpServer(this); if (!tcpServer->listen(QHostAddress::Any, Server::port)) { return; } qDebug() << "Server listening on: " << tcpServer->serverPort(); //! [0] QString ipAddress; QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses(); // use the first non-localhost IPv4 address for (int i = 0; i < ipAddressesList.size(); ++i) { if (ipAddressesList.at(i) != QHostAddress::LocalHost && ipAddressesList.at(i).toIPv4Address()) { ipAddress = ipAddressesList.at(i).toString(); break; } } // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); //! [1] }
void Server::sessionOpened()//change ip address here { // Save the used configuration if (networkSession) { QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) id = networkSession->sessionProperty(QLatin1String("UserChoiceConfiguration")).toString(); else id = config.identifier(); QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } tcpServer = new QTcpServer(this); if (!tcpServer->listen()) { QMessageBox::critical(this, tr("Fortune Server"), tr("Unable to start the server: %1.") .arg(tcpServer->errorString())); close(); return; } QString ipAddress = "127.0.0.1"; //IP AFDRESSSssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss // if we did not find one, use IPv4 localhost if (ipAddress.isEmpty()) ipAddress = QHostAddress(QHostAddress::LocalHost).toString(); qDebug() << "The server is running on:\nIP:"<< ipAddress <<"\nPort:"<< tcpServer->serverPort() <<"\n"; ui->label->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\n" "Waiting for stuff now.") .arg(ipAddress).arg(tcpServer->serverPort())); }
BearerMonitor::BearerMonitor(QWidget *parent) : QWidget(parent) { setupUi(this); #ifdef MAEMO_UI newSessionButton->hide(); deleteSessionButton->hide(); #else delete tabWidget->currentWidget(); sessionGroup->hide(); #endif #if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE) || defined(MAEMO_UI) setWindowState(Qt::WindowMaximized); #endif updateConfigurations(); onlineStateChanged(!manager.allConfigurations(QNetworkConfiguration::Active).isEmpty()); QNetworkConfiguration defaultConfiguration = manager.defaultConfiguration(); for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) { QTreeWidgetItem *item = treeWidget->topLevelItem(i); if (item->data(0, Qt::UserRole).toString() == defaultConfiguration.identifier()) { treeWidget->setCurrentItem(item); showConfigurationFor(item); break; } } connect(&manager, SIGNAL(onlineStateChanged(bool)), this ,SLOT(onlineStateChanged(bool))); connect(&manager, SIGNAL(configurationAdded(const QNetworkConfiguration&)), this, SLOT(configurationAdded(const QNetworkConfiguration&))); connect(&manager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)), this, SLOT(configurationRemoved(const QNetworkConfiguration&))); connect(&manager, SIGNAL(configurationChanged(const QNetworkConfiguration&)), this, SLOT(configurationChanged(const QNetworkConfiguration))); connect(&manager, SIGNAL(updateCompleted()), this, SLOT(updateConfigurations())); #ifdef Q_OS_WIN connect(registerButton, SIGNAL(clicked()), this, SLOT(registerNetwork())); connect(unregisterButton, SIGNAL(clicked()), this, SLOT(unregisterNetwork())); #else nlaGroup->hide(); #endif connect(treeWidget, SIGNAL(itemActivated(QTreeWidgetItem*,int)), this, SLOT(createSessionFor(QTreeWidgetItem*))); connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), this, SLOT(showConfigurationFor(QTreeWidgetItem*))); connect(newSessionButton, SIGNAL(clicked()), this, SLOT(createNewSession())); #ifndef MAEMO_UI connect(deleteSessionButton, SIGNAL(clicked()), this, SLOT(deleteSession())); #endif connect(scanButton, SIGNAL(clicked()), this, SLOT(performScan())); // Just in case update all configurations so that all // configurations are up to date. manager.updateConfigurations(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); QNetworkConfigurationManager manager; if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired) { // Get saved network configuration QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); const QString id = settings.value(QLatin1String("DefaultNetworkConfiguration")).toString(); settings.endGroup(); // If the saved network configuration is not currently discovered use the system default QNetworkConfiguration config = manager.configurationFromIdentifier(id); if ((config.state() & QNetworkConfiguration::Discovered) != QNetworkConfiguration::Discovered) { config = manager.defaultConfiguration(); } QNetworkSession *networkSession = new QNetworkSession(config, &a); networkSession->open(); networkSession->waitForOpened(); if (networkSession->isOpen()) { // Save the used configuration QNetworkConfiguration config = networkSession->configuration(); QString id; if (config.type() == QNetworkConfiguration::UserChoice) { id = networkSession->sessionProperty( QLatin1String("UserChoiceConfiguration")).toString(); } else { id = config.identifier(); } QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); settings.beginGroup(QLatin1String("QtNetwork")); settings.setValue(QLatin1String("DefaultNetworkConfiguration"), id); settings.endGroup(); } } RedDeerNote w; QSplashScreen *splash=new QSplashScreen; splash->setPixmap(QPixmap(":/icons/logord2.png")); splash->show(); splash->showMessage( "Initializing..." ); SleeperThread::msleep(300); splash->showMessage( "Load GUI..." ); SleeperThread::msleep(300); splash->showMessage( "Load Library..." ); SleeperThread::msleep(300); splash->showMessage( "Starting..." ); SleeperThread::msleep(300); w.show(); splash->finish(&w); delete splash; return a.exec(); }
void AsemanNetworkManager::configureChanged(const QNetworkConfiguration &config) { AsemanNetworkManagerItem *item = p->map.value(config.identifier()).value<AsemanNetworkManagerItem*>(); if(item) item->operator =(config); }
void printConfigurationDetails(const QNetworkConfiguration& p) { qDebug() << p.name() <<": isvalid->" <<p.isValid() << " type->"<< p.type() << " roaming->" << p.isRoamingAvailable() << "identifier->" << p.identifier() << " purpose->" << p.purpose() << " state->" << p.state(); }
QT_BEGIN_NAMESPACE /*! \class QNetworkSession \brief The QNetworkSession class provides control over the system's access points and enables session management for cases when multiple clients access the same access point. \since 4.7 \inmodule QtNetwork \ingroup network A QNetworkSession enables control over the system's network interfaces. The session's configuration parameter are determined via the QNetworkConfiguration object to which it is bound. Depending on the type of the session (single access point or service network) a session may be linked to one or more network interfaces. By means of \l{open()}{opening} and \l{close()}{closing} of network sessions a developer can start and stop the systems network interfaces. If the configuration represents multiple access points (see \l QNetworkConfiguration::ServiceNetwork) more advanced features such as roaming may be supported. QNetworkSession supports session management within the same process and depending on the platform's capabilities may support out-of-process sessions. If the same network configuration is used by multiple open sessions the underlying network interface is only terminated once the last session has been closed. \section1 Roaming Applications may connect to the preferredConfigurationChanged() signal in order to receive notifications when a more suitable access point becomes available. In response to this signal the application must either initiate the roaming via migrate() or ignore() the new access point. Once the session has roamed the newConfigurationActivated() signal is emitted. The application may now test the carrier and must either accept() or reject() it. The session will return to the previous access point if the roaming was rejected. The subsequent state diagram depicts the required state transitions. \image roaming-states.png Some platforms may distinguish forced roaming and application level roaming (ALR). ALR implies that the application controls (via migrate(), ignore(), accept() and reject()) whether a network session can roam from one access point to the next. Such control is useful if the application maintains stateful socket connections and wants to control the transition from one interface to the next. Forced roaming implies that the system automatically roams to the next network without consulting the application. This has the advantage that the application can make use of roaming features without actually being aware of it. It is expected that the application detects that the underlying socket is broken and automatically reconnects via the new network link. If the platform supports both modes of roaming, an application indicates its preference by connecting to the preferredConfigurationChanged() signal. Connecting to this signal means that the application wants to take control over the roaming behavior and therefore implies application level roaming. If the client does not connect to the preferredConfigurationChanged(), forced roaming is used. If forced roaming is not supported the network session will not roam by default. Some applications may want to suppress any form of roaming altogether. Possible use cases may be high priority downloads or remote services which cannot handle a roaming enabled client. Clients can suppress roaming by connecting to the preferredConfigurationChanged() signal and answer each signal emission with ignore(). \sa QNetworkConfiguration, QNetworkConfigurationManager */ /*! \enum QNetworkSession::State This enum describes the connectivity state of the session. If the session is based on a single access point configuration the state of the session is the same as the state of the associated network interface. \value Invalid The session is invalid due to an invalid configuration. This may happen due to a removed access point or a configuration that was invalid to begin with. \value NotAvailable The session is based on a defined but not yet discovered QNetworkConfiguration (see \l QNetworkConfiguration::StateFlag). \value Connecting The network session is being established. \value Connected The network session is connected. If the current process wishes to use this session it has to register its interest by calling open(). A network session is considered to be ready for socket operations if it isOpen() and connected. \value Closing The network session is in the process of being shut down. \value Disconnected The network session is not connected. The associated QNetworkConfiguration has the state QNetworkConfiguration::Discovered. \value Roaming The network session is roaming from one access point to another access point. */ /*! \enum QNetworkSession::SessionError This enum describes the session errors that can occur. \value UnknownSessionError An unidentified error occurred. \value SessionAbortedError The session was aborted by the user or system. \value RoamingError The session cannot roam to a new configuration. \value OperationNotSupportedError The operation is not supported for current configuration. \value InvalidConfigurationError The operation cannot currently be performed for the current configuration. */ /*! \fn void QNetworkSession::stateChanged(QNetworkSession::State state) This signal is emitted whenever the state of the network session changes. The \a state parameter is the new state. \sa state() */ /*! \fn void QNetworkSession::error(QNetworkSession::SessionError error) This signal is emitted after an error occurred. The \a error parameter describes the error that occurred. \sa error(), errorString() */ /*! \fn void QNetworkSession::preferredConfigurationChanged(const QNetworkConfiguration& config, bool isSeamless) This signal is emitted when the preferred configuration/access point for the session changes. Only sessions which are based on service network configurations may emit this signal. \a config can be used to determine access point specific details such as proxy settings and \a isSeamless indicates whether roaming will break the sessions IP address. As a consequence to this signal the application must either start the roaming process by calling migrate() or choose to ignore() the new access point. If the roaming process is non-seamless the IP address will change which means that a socket becomes invalid. However seamless mobility can ensure that the local IP address does not change. This is achieved by using a virtual IP address which is bound to the actual link address. During the roaming process the virtual address is attached to the new link address. Some platforms may support the concept of Forced Roaming and Application Level Roaming (ALR). Forced roaming implies that the platform may simply roam to a new configuration without consulting applications. It is up to the application to detect the link layer loss and reestablish its sockets. In contrast ALR provides the opportunity to prevent the system from roaming. If this session is based on a configuration that supports roaming the application can choose whether it wants to be consulted (ALR use case) by connecting to this signal. For as long as this signal connection remains the session remains registered as a roaming stakeholder; otherwise roaming will be enforced by the platform. \sa migrate(), ignore(), QNetworkConfiguration::isRoamingAvailable() */ /*! \fn void QNetworkSession::newConfigurationActivated() This signal is emitted once the session has roamed to the new access point. The application may reopen its socket and test the suitability of the new network link. Subsequently it must either accept() or reject() the new access point. \sa accept(), reject() */ /*! \fn void QNetworkSession::opened() This signal is emitted when the network session has been opened. The underlying network interface will not be shut down as long as the session remains open. Note that this feature is dependent on \l{QNetworkConfigurationManager::SystemSessionSupport}{system wide session support}. */ /*! \fn void QNetworkSession::closed() This signal is emitted when the network session has been closed. */ /*! Constructs a session based on \a connectionConfig with the given \a parent. \sa QNetworkConfiguration */ QNetworkSession::QNetworkSession(const QNetworkConfiguration& connectionConfig, QObject* parent) : QObject(parent), d(0) { foreach (QBearerEngine *engine, qNetworkConfigurationManagerPrivate()->engines()) { if (engine->hasIdentifier(connectionConfig.identifier())) { d = engine->createSessionBackend(); d->q = this; d->publicConfig = connectionConfig; d->syncStateWithInterface(); connect(d, SIGNAL(quitPendingWaitsForOpened()), this, SIGNAL(opened())); connect(d, SIGNAL(error(QNetworkSession::SessionError)), this, SIGNAL(error(QNetworkSession::SessionError))); connect(d, SIGNAL(stateChanged(QNetworkSession::State)), this, SIGNAL(stateChanged(QNetworkSession::State))); connect(d, SIGNAL(closed()), this, SIGNAL(closed())); connect(d, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool)), this, SIGNAL(preferredConfigurationChanged(QNetworkConfiguration,bool))); connect(d, SIGNAL(newConfigurationActivated()), this, SIGNAL(newConfigurationActivated())); break; } }