//!-------------------------------------------------------------------------------------------------------------------------------- //! //! \brief pissServer::incomingConnection //! \param sd //! void pissServer::run(){ while(flag){ SOCKET sClient; if(INVALID_SOCKET == (sClient = ::accept(this->socketServer, NULL, NULL))){ continue; } qDebug()<<"accept client"; //! disable nagle char value = 1; setsockopt(sClient, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value)); //! set the mode of the socket to be nonblocking u_long iMode = 1; int iResult = ioctlsocket(sClient, FIONBIO, &iMode); if(iResult == SOCKET_ERROR){ printf("ioctlsocket failed with error: %d\n", WSAGetLastError()); closesocket(sClient); WSACleanup(); exit(1); } emit incomingConnection(sClient); } }
ClientConnectionManager::ClientConnectionManager(QObject *parent) : QObject(parent), mServer(this), mRequestMan(this) { connect(&mServer,SIGNAL(newConnection()),this,SLOT(incomingConnection())); connect(&mRequestMan,SIGNAL(returnMessageReady(QTcpSocket*,QByteArray)), this,SLOT(sendReturnMessage(QTcpSocket*,QByteArray))); }
TripClient::TripClient(const QString ipAddress, const quint16 port, const SocketType socketType) : QAbstractSocket(socketType, NULL), m_ipAddress(ipAddress), m_port(port) { this->showStartupOptions(); connect(this,SIGNAL(log(QString)),SLOT(logMessage(QString))); if(this->socketType() == QAbstractSocket::TcpSocket) { // connect(this,SIGNAL(disconnected()),SLOT(deleteLater())); if(m_ipAddress.contains("localhost")) this->connectToHost(QHostAddress::LocalHost, m_port); else this->connectToHost(QHostAddress(m_ipAddress), m_port); if( !this->waitForConnected( 1000 ) ) { emit log("\n>> Failed connect to server."); exit(9); } else { emit log("Client has connected to the server."); this->receiveData(); } } else { UDPSocket = new QUdpSocket(this); UDPSocket->bind(QHostAddress(m_ipAddress),m_port+1,QUdpSocket::ShareAddress); this->sendUDPCommandGET(); connect(UDPSocket,SIGNAL(readyRead()),SLOT(incomingConnection())); } }
Server::Server(QWidget *parent) : QDialog(parent), tcpServer(0), clientConnection(0) { bool test = true; statusLabel = new QLabel; quitButton = new QPushButton(tr("Quit")); quitButton->setAutoDefault(false); 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(); portNum = 27015; tcpServer = new QTcpServer(this); if (!tcpServer->listen(QHostAddress(ipAddress), portNum)) // "10.8.95.35"), 27015 { QMessageBox::critical(this, tr("Fortune Server"), tr("Unable to start the server: %1.").arg(tcpServer->errorString())); close(); return; } statusLabel->setText(tr("The server is running on\n\nIP: %1\nport: %2\n\nRun the Fortune Client example now.") .arg(ipAddress).arg(tcpServer->serverPort())); fortunes << tr("111") << tr("222") << tr("333") << tr("444"); connect(quitButton, SIGNAL(clicked()), this, SLOT(close())); connect(tcpServer, SIGNAL(newConnection()), this, SLOT(incomingConnection())); QHBoxLayout *buttonLayout = new QHBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(quitButton); buttonLayout->addStretch(1); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(statusLabel); mainLayout->addLayout(buttonLayout); setLayout(mainLayout); setWindowTitle(tr("Fortune Server")); }
void Core::init() { CoreSettings cs; // legacy QVariantMap dbsettings = cs.storageSettings().toMap(); _configured = initStorage(dbsettings.value("Backend").toString(), dbsettings.value("ConnectionProperties").toMap()); if (Quassel::isOptionSet("select-backend")) { selectBackend(Quassel::optionValue("select-backend")); exit(0); } if (!_configured) { if (!_storageBackends.count()) { qWarning() << qPrintable(tr("Could not initialize any storage backend! Exiting...")); qWarning() << qPrintable(tr("Currently, Quassel supports SQLite3 and PostgreSQL. You need to build your\n" "Qt library with the sqlite or postgres plugin enabled in order for quasselcore\n" "to work.")); exit(1); // TODO make this less brutal (especially for mono client -> popup) } qWarning() << "Core is currently not configured! Please connect with a Quassel Client for basic setup."; } if (Quassel::isOptionSet("add-user")) { createUser(); exit(0); } if (Quassel::isOptionSet("change-userpass")) { changeUserPass(Quassel::optionValue("change-userpass")); exit(0); } connect(&_server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); connect(&_v6server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); if (!startListening()) exit(1); // TODO make this less brutal if (Quassel::isOptionSet("oidentd")) _oidentdConfigGenerator = new OidentdConfigGenerator(this); }
bool DebugSession::listenForConnection(QString& error) { Q_ASSERT(!m_server); m_server = new QTcpServer(this); kDebug(); int remotePortSetting = m_launchConfiguration->config().readEntry("RemotePort", 9000); if(m_server->listen(QHostAddress::Any, remotePortSetting)) { connect(m_server, SIGNAL(newConnection()), this, SLOT(incomingConnection())); } else { error = i18n("Opening port %1 failed: %2.", remotePortSetting, m_server->errorString()); kWarning() << "Error" << m_server->errorString(); delete m_server; m_server = 0; return false; } return m_server->isListening(); }
void TripClient::incomingConnection() { emit log("Client has connected to the server."); QByteArray baDatagram; baDatagram.resize(UDPSocket->pendingDatagramSize()); UDPSocket->readDatagram(baDatagram.data(), baDatagram.size()); QDataStream in(&baDatagram, QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_4_7); in >> fileSize; disconnect(UDPSocket,SIGNAL(readyRead()),this,SLOT(incomingConnection())); connect(UDPSocket,SIGNAL(readyRead()),this,SLOT(processPendingDatagrams())); emit log("\nReceiving data from server, wating."); pos = 0; step = 0; transferStartTime = QTime::currentTime(); }
void sipQTcpServer::sipProtectVirt_incomingConnection(bool sipSelfWasArg,qintptr a0) { (sipSelfWasArg ? QTcpServer::incomingConnection(a0) : incomingConnection(a0)); }