コード例 #1
0
ファイル: server.cpp プロジェクト: ext5/CopyQ
void Server::start()
{
    while (m_server->hasPendingConnections())
        onNewConnection();

    connect( m_server, SIGNAL(newConnection()),
             this, SLOT(onNewConnection()) );
}
コード例 #2
0
ファイル: CWebSocketServer.cpp プロジェクト: CRLG/LABOTBOX
// =====================================================================
//                       WebSocket Server
// =====================================================================
// _____________________________________________________________________
void CWebSocketServer::open(tNtwConfig cfg)
{
    //qDebug() << "CWebSocketServer::open";
    if (!m_pWebSocketServer) {
        m_pWebSocketServer = new QWebSocketServer(QStringLiteral("WebSocketTcpServer"),
                                                  QWebSocketServer::NonSecureMode,
                                                  this);
    }
    unsigned long port = cfg["port"].toUInt();
    QString errorMsg = "Unable to connect WebSocketServer to port " +  QString::number(port);
    if (m_pWebSocketServer) {
        if (m_pWebSocketServer->listen(QHostAddress::Any, port))
        {
            connect(m_pWebSocketServer, SIGNAL(newConnection()),
                    this,               SLOT(onNewConnection()));
            QString msg = "WebSocketServer listening on port " + QString::number(port);
            emit opened(msg);
        }
        else {
            emit errorMessage(errorMsg);
        }
    }
    else {
        emit errorMessage(errorMsg);
    }
}
コード例 #3
0
ファイル: tcpgatedialog.cpp プロジェクト: wtpluscn/wttools
void TcpGateDialog::InitListen()
{
	m_ndListen.group = ui->gbListen;
	m_ndListen.cbIp = ui->cbLIP;
	m_ndListen.spinPort = ui->spinLPort;
	m_ndListen.lnSend = ui->lnLSendBytes;
	m_ndListen.lnRecv = ui->lnLRecvBytes;
	m_ndListen.leStatus = ui->leLStatus;
	m_ndListen.btnStart = ui->btnListen;	
	connect(m_ndListen.btnStart, SIGNAL(clicked()), this, SLOT(onClkBtnListen()));
		
	m_ndListen.bConnected = false;
	m_ndListen.bStarted = false;
	m_ndListen.nSendBytes = 0;
	m_ndListen.nRecvBytes = 0;	
	QSettings setting;
	m_ndListen.latestIpList = setting.value("TcpGateTest/Listen/LatestIP", "").toStringList();
	int nCount = m_ndListen.latestIpList.count();
	for (int i = nCount-1; i >= 0; i--)
	{
		if (!m_ndListen.latestIpList[i].isEmpty())
		{
			m_ndListen.cbIp->addItem(m_ndListen.latestIpList[i]);
		}
	}
	
	m_ndListen.tcpSocket = NULL;	
	m_ndListen.tcpServer = new QTcpServer(this);
	connect(m_ndListen.tcpServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));	
	m_ndListen.spinPort->setValue(setting.value("TcpGateTest/Listen/LatestPort", 5100).toInt());	
}
コード例 #4
0
LegacyPlayerListener::LegacyPlayerListener( QObject* parent )
                    : QTcpServer( parent )
{
    connect( this, SIGNAL(newConnection()), SLOT(onNewConnection()) );
    if (!listen( QHostAddress::LocalHost, port() ))
        qWarning() << "Couldn't start legacy player listener";
}
コード例 #5
0
TinyWebServer::TinyWebServer( QObject* parent )
    : QObject( parent )
{
    m_tcpServer = new QTcpServer( this );
    m_tcpServer->listen( QHostAddress( QHostAddress::LocalHost ), 0 );
    connect( m_tcpServer, SIGNAL( newConnection() ), SLOT( onNewConnection() ) );
}
コード例 #6
0
ファイル: masterserver.cpp プロジェクト: David-Hanna/UPEIGame
MasterServer::MasterServer(QObject *parent) :
    QObject(parent)
{
    gameServers = new QVector<GameServer>();
    server = new QTcpServer(this);
    connect(server, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
}
コード例 #7
0
QT_USE_NAMESPACE

//! [constructor]
SslEchoServer::SslEchoServer(quint16 port, QObject *parent) :
    QObject(parent),
    m_pWebSocketServer(Q_NULLPTR),
    m_clients()
{
    m_pWebSocketServer = new QWebSocketServer("SSL Echo Server", QWebSocketServer::SECURE_MODE, this);
    QSslConfiguration sslConfiguration;
    QFile certFile(QStringLiteral("./localhost.cert"));
    QFile keyFile(QStringLiteral("./localhost.key"));
    certFile.open(QIODevice::ReadOnly);
    keyFile.open(QIODevice::ReadOnly);
    QSslCertificate certificate(&certFile, QSsl::Pem);
    QSslKey sslKey(&keyFile, QSsl::Rsa, QSsl::Pem);
    certFile.close();
    keyFile.close();
    sslConfiguration.setProtocol(QSsl::AnyProtocol);
    sslConfiguration.setPeerVerifyMode(QSslSocket::VerifyNone);
    sslConfiguration.setLocalCertificate(certificate);
    sslConfiguration.setPrivateKey(sslKey);
    sslConfiguration.setProtocol(QSsl::TlsV1SslV3);
    m_pWebSocketServer->setSslConfiguration(sslConfiguration);

    if (m_pWebSocketServer->listen(QHostAddress::Any, port))
    {
        qDebug() << "SSL Echo Server listening on port" << port;
        connect(m_pWebSocketServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
    }
}
コード例 #8
0
ファイル: qsocketpair.cpp プロジェクト: Kuipers/qhttpengine
QSocketPair::QSocketPair()
    : mServerSocket(0)
{
    connect(&mServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));

    mServer.listen(QHostAddress::LocalHost);
    mClientSocket.connectToHost(mServer.serverAddress(), mServer.serverPort());
}
コード例 #9
0
TelepathyClient::TelepathyClient(QObject *parent) :
    AbstractClient(parent), server(NULL) {

    // Register to handler
    TelepathyHandler::instance()->setClient(this);

    server = new QTcpServer(this);
    connect(server, SIGNAL(newConnection()), SLOT(onNewConnection()));
}
コード例 #10
0
ファイル: BridgeServer.cpp プロジェクト: Archie3d/sandboxer
BridgeServer::BridgeServer(QObject *pParent)
    : QObject(pParent)
{
    m_pipeName = generateRandomPipeName();
    m_pLocalServer = new QLocalServer(this);
    m_pLocalServer->setMaxPendingConnections(1);
    connect(m_pLocalServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
    m_pBridgeCommunicator = nullptr;
}
コード例 #11
0
ファイル: NSocket.cpp プロジェクト: aaronps/nsocket
/*
 * sysAccept
 */
void
NSocketX::sysAccept()
{
    char new_ipaddress[NI_MAXHOST];
    char new_port[NI_MAXSERV];
    NSocket * newcon;
    SOCKET new_fd;
    sockaddr_storage new_ssaddr;
    socklen_t slen = sizeof(new_ssaddr);

    new_fd = accept(fd,(struct sockaddr *) &new_ssaddr, &slen);
    if ( new_fd == INVALID_SOCKET )
    {
        error=GET_NET_ERROR();
        switch (error)
        {
        // Notify on BAD errors, the rest are ignorable
        // Note that this errors are NSocket errors
#ifdef _WIN32
            // for windows
            case WSAENOTSOCK:
            case WSAEOPNOTSUPP:
            case WSAEINVAL:
            case WSAEFAULT:
            case WSANOTINITIALISED:
#else
            // for others
            case EBADF:
            case ENOTSOCK:
            case EOPNOTSUPP:
            case EINVAL: // not in macosx, should test if this compiles in it
            case EFAULT:
#endif
                notifyError(); // on this errors this socket should be closed
        }
        return; // nothing more to do
    }

    sockaddr_to_ip(&new_ssaddr,slen,new_ipaddress,new_port);

    newcon=onNewConnection(new_ipaddress, new_port);
    if (newcon)
    {
        newcon->fd = new_fd;
        newcon->has_socket = true;
        strcpy(newcon->ipaddress, new_ipaddress);
        strcpy(newcon->port, new_port);
        //NSocketManager::add_to_list(newcon);
        newcon->onSocketReady();
    }
    else
    {
        closesocket(new_fd);
    }
}
コード例 #12
0
void RelayStation::start()
{
    qDebug() << "Starting to listen to port " << port;

    if (!webserver->listen(QHostAddress::Any, port)) {
        qDebug() << "Failure to listen to port " << port;
        return;
    }

    connect(webserver, SIGNAL(newConnection()), SLOT(onNewConnection()));
}
コード例 #13
0
ファイル: mainwindow.cpp プロジェクト: Erichappy/qt_chatRoom
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("聊天服务器");
    ip = "127.0.0.1";
    port = 8888;
    server = new QTcpServer(this);
    connect(server, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
}
コード例 #14
0
ファイル: tcpbuilder.cpp プロジェクト: albert-mirzoyan/qfcgi
bool QFCgiTcpConnectionBuilder::listen() {
  if (this->server->listen(this->address, this->port)) {
    connect(this->server, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
    qDebug("FastCGI application started, listening on %s/%d",
      qPrintable(this->server->serverAddress().toString()),
      this->server->serverPort());
    return true;
  } else {
    return false;
  }
}
コード例 #15
0
ファイル: fakehttpserver.cpp プロジェクト: chenbk85/librapid
void FakeHttpServer::start() {
	server_.startListening([this](rapid::ConnectionPtr pConn) {
		pConn->setSendEventHandler([this](rapid::ConnectionPtr conn) {
			onNewConnection(conn);
		});

		pConn->setReceiveEventHandler([this](rapid::ConnectionPtr conn) {
			onNewConnection(conn);
		});

		pConn->setAcceptEventHandler([this](rapid::ConnectionPtr conn) {
			onNewConnection(conn);
		});
	});
	RAPID_LOG_INFO() << "HttpServer starting...";
	RAPID_LOG_INFO() << "Press 'Ctrl+C' to stop";
	std::unique_lock<std::mutex> lock(waitStopMutex_);
	stopFlag_.wait(lock);
	server_.shutdown();
}
コード例 #16
0
SocketListener::SocketListener(QObject* parent) : QObject(parent) {
	//	Remove socket file if exists. Can safely do this
	//	because the only case we could reach this point
	//	is if connection to existing socket failed. That's
	//	why if the socket path still exists, it isn't accociated
	//	with any sockets
	if ( QFile::exists(AppInfo::socketPath()) )
		QFile::remove(AppInfo::socketPath());
	server_ = new QLocalServer();
	connect(server_, SIGNAL(newConnection()), SLOT(onNewConnection()));
}
コード例 #17
0
ファイル: sender.cpp プロジェクト: coslyk/fileconveyor
void Sender::startTask(const QString &filepath) {
    if (server)
        return;
    this->filepath = filepath;
    server = new QTcpServer(this);
    connect(server, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
    if (!server->listen(QHostAddress::Any, 8001))
        server->listen();
    label->setText(QString("%1\n%2:%3").arg(tr("Please enter the following address in receiver:"),
                                            Utils::getMyAddress(),
                                            QString::number(server->serverPort())));
}
コード例 #18
0
ファイル: echoserver.cpp プロジェクト: antoshib/QWebSockets
//! [constructor]
EchoServer::EchoServer(quint16 port, QObject *parent) :
	QObject(parent),
	m_pWebSocketServer(0),
	m_clients()
{
	m_pWebSocketServer = new WebSocketServer(this);
	if (m_pWebSocketServer->listen(QHostAddress::Any, port))
	{
		qDebug() << "Echoserver listening on port" << port;
		connect(m_pWebSocketServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
	}
}
コード例 #19
0
ファイル: LuaTcpConsole.cpp プロジェクト: jmckaskill/qsmp
QSMP_BEGIN

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

LuaTcpServer::LuaTcpServer()
{
  connect(&server_,SIGNAL(newConnection()),SLOT(onNewConnection()));
  bool listening = server_.listen(QHostAddress::Any,QSMP_LUA_CONSOLE_PORT);
  assert(listening);
}
コード例 #20
0
ファイル: Acceptor.cpp プロジェクト: chjp2046/wangle
void
Acceptor::connectionReady(
    AsyncSocket::UniquePtr sock,
    const SocketAddress& clientAddr,
    const string& nextProtocolName,
    TransportInfo& tinfo) {
  // Limit the number of reads from the socket per poll loop iteration,
  // both to keep memory usage under control and to prevent one fast-
  // writing client from starving other connections.
  sock->setMaxReadsPerEvent(16);
  tinfo.initWithSocket(sock.get());
  onNewConnection(std::move(sock), &clientAddr, nextProtocolName, tinfo);
}
コード例 #21
0
bool CharmTCPCommandServer::listen()
{
    if (!m_server->listen(m_address, m_port)) {
        qWarning("Failed to bind to %s:%d", qPrintable(m_address.toString()), m_port);
        return false;
    }

    connect(m_server, SIGNAL(newConnection()), SLOT(onNewConnection()));

    m_discoveryTimer = startTimer(sCharmDiscoveryBroadcastRate);

    return true;
}
コード例 #22
0
QT_USE_NAMESPACE

//! [constructor]
ChatServer::ChatServer(quint16 port, QObject *parent) :
    QObject(parent),
    m_pWebSocketServer(Q_NULLPTR),
    m_clients()
{
    m_pWebSocketServer = new QWebSocketServer("Chat Server", QWebSocketServer::NON_SECURE_MODE, this);
    if (m_pWebSocketServer->listen(QHostAddress::Any, port))
    {
        qDebug() << "Chat Server listening on port" << port;
        connect(m_pWebSocketServer, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
    }
}
コード例 #23
0
ファイル: servatrice.cpp プロジェクト: clau911015/Cockatrice
Servatrice_WebsocketGameServer::Servatrice_WebsocketGameServer(Servatrice *_server, int /* _numberPools */, const QSqlDatabase &_sqlDatabase, QObject *parent)
    : QWebSocketServer("Servatrice", QWebSocketServer::NonSecureMode, parent),
      server(_server)
{
    // Qt limitation: websockets can't be moved to another thread
    Servatrice_DatabaseInterface *newDatabaseInterface = new Servatrice_DatabaseInterface(WEBSOCKET_POOL_NUMBER, server);
    Servatrice_ConnectionPool *newPool = new Servatrice_ConnectionPool(newDatabaseInterface);

    server->addDatabaseInterface(thread(), newDatabaseInterface);
    newDatabaseInterface->initDatabase(_sqlDatabase);

    connectionPools.append(newPool);

    connect(this, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
}
コード例 #24
0
XmlRpcServer::XmlRpcServer( QObject *parent, const QString &cert, const QString &key, const QByteArray & ) :
    QTcpServer( parent )
{
    #ifdef DEBUG_XMLRPC
    qDebug() << this << "XmlRpcServer(): parent" << parent;
    #endif
    #ifndef QT_NO_OPENSSL
    if ( !cert.isEmpty() && !key.isEmpty() )
        sslParams = new SslParams( cert, key );
    else
        sslParams = NULL;
    #endif

    connect(this, SIGNAL(newConnection()), this, SLOT(onNewConnection()) );
}
コード例 #25
0
PlayerListener::PlayerListener( QObject* parent ) throw( std::runtime_error )
              : QLocalServer( parent )
{
    connect( this, SIGNAL(newConnection()), SLOT(onNewConnection()) );

#ifdef WIN32
    std::string s;
    DWORD r = scrobSubPipeName( &s );
    if (r != 0) throw std::runtime_error( formatWin32Error( r ) );
    QString const name = QString::fromStdString( s );
#else
    QString const name = "lastfm_scrobsub";
#endif
    
    if (!listen( name ))
        throw std::runtime_error( errorString().toStdString() );
}
コード例 #26
0
ファイル: SocketServer.cpp プロジェクト: alex-games/a1
SocketServer::SocketServer(const QString s, QObject *parent)
  : QThread(parent), _session(s) { 
  qRegisterMetaType<QAbstractSocket::SocketError>
    ("QAbstractSocket::SocketError");
    
    _tcpServer = new QTcpServer;

    connect(_tcpServer, SIGNAL(newConnection()), SLOT(onNewConnection()));

    connect(_tcpServer, SIGNAL(disconnected()), SLOT(onDisconnect())); 
//    connect(_socket, SIGNAL(readyRead()), SLOT(onReadyRead())); 
    connect(_tcpServer, SIGNAL(error(QAbstractSocket::SocketError)),
	    SLOT(onError(QAbstractSocket::SocketError))); 

    _port = 4244;
    openSocket();
  
}
コード例 #27
0
ファイル: moc_server.cpp プロジェクト: Freshield/LEARNING_QT
int Server::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QDialog::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: on_pushButton_clicked(); break;
        case 1: readMessage((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 2: onNewConnection(); break;
        case 3: DeleteOneClient((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 4: on_setButton_clicked(); break;
        case 5: on_send_all_pushButton_clicked(); break;
        default: ;
        }
        _id -= 6;
    }
    return _id;
}
コード例 #28
0
ファイル: moc_proxy.cpp プロジェクト: max3raza/sipEC
int Proxy::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: onNewConnection(); break;
        case 1: onConnected(); break;
        case 2: onOutSocketStateChanged(); break;
        case 3: onInSockeStateChanged(); break;
        case 4: onReadyInSocket(); break;
        case 5: onReadyOutSocket(); break;
        default: ;
        }
        _id -= 6;
    }
    return _id;
}
コード例 #29
0
ファイル: funq.cpp プロジェクト: Helius/funq
void Funq::funqInit() {
    if (m_mode == Funq::PLAYER) {
        m_server = new QTcpServer(this);
        connect(m_server, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
        if (!m_server->listen(QHostAddress::LocalHost, m_port)) {
            qDebug() << "Unable to initialize funq. Error:\n\t"
                     << m_server->errorString();
        } else {
            qDebug() << "funq is initialized on port " << m_port << ".";
        }
    } else {
        m_pick = new Pick(new PickFormatter);
        if (registerPick()) {
            qDebug() << "Funq mode PICK in action !";
        } else {
            qDebug() << "Internal error, unable to use the PICK funq mode.";
        }
    }
}
コード例 #30
0
ファイル: QTNServer.cpp プロジェクト: darongE/QTNetworkDemo
bool QTNServer::init()
{
    std::cout << getStatusDescription().c_str() << "is initializing " << "ip: " << SERVER_IP << ", port: " << SERVER_PORT << "\n";

    bool isInitialized = listen(QHostAddress(SERVER_IP), SERVER_PORT);
    if (isInitialized)
    {
        m_serverStatus = SERVER_STATUS_OK;
        std::cout << getStatusDescription().c_str() << "is listening\n";
        QThreadPool::globalInstance()->setMaxThreadCount(QTNConst::NUM_MAX_CLIENTS);
        connect(this, SIGNAL(newConnection()), this, SLOT(onNewConnection()));
        QTimer::singleShot(1000, this, SLOT(printClients()));
    }
    else
    {
        m_serverStatus = SERVER_STATUS_NOK;
        std::cout << getStatusDescription().c_str() << "is NOT listening\n";
    }

    return isInitialized;
}