Exemple #1
0
Server::Server(QWidget *parent) :
	QDialog(parent),
	mTcpServer(0),
	mNetworkSession(0) {
	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();
		}

		mNetworkSession = new QNetworkSession(config, this);
		connect(mNetworkSession, SIGNAL(opened()), this, SLOT(sessionOpened()));

		mNetworkSession->open();
	} else {
		sessionOpened();
	}

	mIPAddressMapper = new QSignalMapper;
	connect(mTcpServer, SIGNAL(newConnection()), this, SLOT(acceptClientConnection()));
	connect(mIPAddressMapper, SIGNAL(mapped(QString)), this, SIGNAL(clientDisconnected(QString)));
}
Exemple #2
0
/**
 * @details
 * Run the TCP server, listening for incoming client requests
 */
void TCPConnectionManager::run()
{
    // start TCP Server, which listens for incoming connections
    if (!_tcpServer -> listen( QHostAddress::Any, _port))
        std::cerr << QString("Unable to start QTcpServer: %1").arg( _tcpServer -> errorString()).toStdString();
    else
        connect(_tcpServer, SIGNAL(newConnection()), this, SLOT(acceptClientConnection()), Qt::DirectConnection );

}
void ClientTestServer::run()
{
    _server = new QTcpServer;
    if ( ! _server->listen(QHostAddress::Any, 0) ) {
        std::cerr << QString("Unable to start QTcpServer: %1").arg( _server -> errorString()).toStdString();
        return;
    }
    else
        connect(_server, SIGNAL(newConnection()), this, SLOT(acceptClientConnection()), Qt::DirectConnection );
    exec();
    delete _server;
}
void TCPServer::ListenOn()
{
	while(1){
		acceptClientConnection();
	}
}