예제 #1
0
//FD_SETs are populated,
void ServerManager::processInput() {
	handleNewConnection();
	//	cm->handleExceptions();
	//Check 
	cm->getInputFromClients();

}
예제 #2
0
Server::Server(Game *game, QHostAddress addr, int port): cerr(stderr, QIODevice::WriteOnly)
{
    this->game=game;
    this->socket=NULL;
    // vytvorime TCP server
    this->server = new QTcpServer(this);

    // zajistime zpracovani pozadavku vlastnim slotem
    connect(this->server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));

    // explicitne zakazeme pouziti proxy 
    this->server->setProxy(QNetworkProxy::NoProxy);
    // nastavime max. poèet spojení
    this->server->setMaxPendingConnections(50);

    // nastavíme IP a port pro naslouchani
    bool listening = this->server->listen(addr, port);

    // pokud se TCP server nepodarilo spustit na dané IP a portu
    if(not listening)
    {
        this->game->printInfo(ERROR,QString("Server error"),QString("Server couldn't have been started"));
    }
    else{
        this->game->printInfo(INFO,QString("Server created"),QString("Server successfully created! Now waiting for a client to connect."));
    }

}
예제 #3
0
Server::Server(QWidget *parent) : QWidget(parent)
{

    sslServer = new SSLServer(this);
    if (!sslServer->listen()) {
        QMessageBox::critical(this, tr("Secure Fortune Server"),
                              tr("Unable to start the server: %1.")
                              .arg(sslServer->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();


    qDebug() << (tr("The server is running on\n\nIP: %1\nport: %2\n\n"
                            "Run the Secure Fortune Client example now.")
                         .arg(ipAddress).arg(sslServer->serverPort()));


    /*fortunes << tr("You've been leading a dog's life. Stay off the furniture.")
             << tr("You can always think about tomorrow later...")
             << tr("You will be surprised by a loud noise.")
             << tr("The Hokies will not be ACC champs this year. Maybe next?")
             << tr("Notre Dame in the ACC?! Give me a break!!")
             << tr("If only Blacksburg had a Trader Joes!!")
             << tr("You will feel hungry again in another hour.")
             << tr("Thank goodness we now have a Chipoltes.")
             << tr("Your time would be better spent tweeting.")
             << tr("You cannot kill time without injuring eternity.")
             << tr("You can do anything with Qt.")
             << tr("Computers are not intelligent. They only think they are.")
             << tr("Security is important as your clasmates are always wiresharking your traffic.")
             << tr("You will survive ECE 3574.");*/
    //connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    connect(sslServer, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));

    //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("Secure Fortune Server"));
}
예제 #4
0
int main()
{
	GOOGLE_PROTOBUF_VERIFY_VERSION;

	boost::asio::io_service ioService;
	boost::asio::io_service::work work(ioService);

	std::thread myThread(
		[&ioService]()
		{
			std::cout << "io_service thread id: ";
			std::cout << std::this_thread::get_id() << std::endl;
			ioService.run();
		});

	//
	// Only allowed to have one acceptor listening on a port at at time.
	// Therefore, creating it one time here and passing it into the handleNewConnection function.
	std::shared_ptr<ip::tcp::acceptor> acceptor = std::make_shared<ip::tcp::acceptor>(ioService, ip::tcp::endpoint(ip::tcp::v4(), 12345));

	handleNewConnection(ioService, acceptor);
	myThread.join();

	return 0;
}
예제 #5
0
파일: Server.cpp 프로젝트: kiwon0905/PT
void Server::run()
{
	sf::Clock stepClock, syncClock;
	sf::Time elapsedStep = sf::Time::Zero, elapsedSync = sf::Time::Zero;
	
	while (true)
	{
		handleNewConnection();
		handleDisconnection();
		handlePackets();


		elapsedStep += stepClock.restart();
		elapsedSync += syncClock.restart();


		while (elapsedStep >= TimeStep)
		{
			elapsedStep -= TimeStep;
			mGame.step(*this);
		}
		while (elapsedSync >= TimeSync)
		{
			elapsedSync -= TimeSync;
			mGame.sync(*this);
		}

	}
}
TNotificationServer::TNotificationServer(QObject *parent) :  QTcpServer(parent) {
	//timer = new QTimer;
	//connect(timer,SIGNAL(timeout()),this,SLOT(handleTimer()));
	//timer->start(TIMER_PERIOD);

	listen(QHostAddress::Any, OUT_SOCKET_PORT);
	connect(this,SIGNAL(newConnection()),this,SLOT(handleNewConnection()));
	waitForNewConnection();
}
static void _as_activateAs(AS* h, int sd, uint32_t events) {
	struct partner_s *partner;
	int lsd = sd;
	partner = g_hash_table_lookup(h->hashmap, &lsd);

	if (partner == NULL && !IS_NEW_CONNECTION(sd)) {
		h->slogf(SHADOW_LOG_LEVEL_DEBUG, __FUNCTION__,
				"Null pointer in lookup of %d (partner).", sd);
		_exit(EXIT_FAILURE);
	}

	h->slogf(SHADOW_LOG_LEVEL_MESSAGE, __FUNCTION__,
			"In the activate %d.", sd);

	if(events & EPOLLIN) {
		int res = 0;
		h->slogf(SHADOW_LOG_LEVEL_DEBUG, __FUNCTION__,
				"EPOLLIN is set %d", sd);
		if (IS_NEW_CONNECTION(sd))
			handleNewConnection(h, sd);
		else
			res = handleRead(h, sd, partner);

		if (res > 0) {
			/* close the connection, some error (like EPIPE)
			 * occurred in the read. */
			closeConnections(h, sd, partner);
		} else if (res < 0) {
			/* Fatal error occurred. */
			_exit(EXIT_FAILURE);
		}
	}

	if(events & EPOLLOUT) {
		struct partner_s *me = g_hash_table_lookup(h->hashmap, &partner->sd);

		if (me == NULL) {
			if (h->isDone == 1){
				/* If it reaches this point, it means that the other 
			   		end point closed its socket descriptior (connection closed).
			   		Thus this socked descriptor must be closed too. */
				closeConnections(h, sd, partner);
			}else{
				h->slogf(SHADOW_LOG_LEVEL_DEBUG, __FUNCTION__,
					"Null pointer in lookup of %d (me) (connection closed).", sd);
				_exit(EXIT_FAILURE);
			}
		}else{

			h->slogf(SHADOW_LOG_LEVEL_DEBUG, __FUNCTION__,
				"EPOLLOUT is set %d", sd);
			handleWrite(h, sd, partner->sd, me);
		}
	}

}
예제 #8
0
Handover::Handover(quint16 serverPort, QObject *parent)
:   QObject(parent), m_server(new QLlcpServer(this)),
    m_client(new QLlcpSocket(this)), m_remote(0), m_serverPort(0), m_localServerPort(serverPort)
{
    connect(m_server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
    m_server->listen(tennisUri);

    connect(m_client, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
    connect(m_client, SIGNAL(readyRead()), this, SLOT(readBluetoothService()));

    m_client->connectToService(0, tennisUri);
}
예제 #9
0
//note: it can take a while before the listen socket is actually on... So if you immediately start an upload
//after starting this thread, you might be rejected..
void UploadManager::run() {

	int new_fd;
	fd_set fd;
	timeval tv; //timeout for select, so that the keepRunning flag is regularly checked and thread can be stopped
	tv.tv_sec = 1;
	tv.tv_usec = 0;
	struct sockaddr_storage client_addr; // client address information
	socklen_t sin_size;

	int port = listenPort;

	while((listenFD = openListenSocket(port)) < 0){
		port++;

		if ((port-listenPort) > 5)
			return;
		//return; //stop the UploadManager
	}

	std::cout << "UploadManager listening on port " << port << std::endl;

	while (keepRunning) {  // main accept() loop
		FD_ZERO(&fd);
		FD_SET(listenFD, &fd);
		if (select(listenFD + 1, &fd, NULL, NULL, &tv) > 0) {
			sin_size = sizeof client_addr;
			std::cout << "New connection detected" << std::endl;
			new_fd = accept(listenFD, (struct sockaddr *) &client_addr, &sin_size);
			if (new_fd == -1) {
				std::cerr << "accept" << strerror(errno) << std::endl;
				continue;
			}

			char s[INET6_ADDRSTRLEN];
			inet_ntop(client_addr.ss_family,
					get_in_addr((struct sockaddr *) &client_addr), s, sizeof s);

			std::cout << "Got connection from " << s << " on FD" << new_fd
					<< std::endl;

			handleNewConnection(new_fd);
		} //time-out of select, evaluate if thread should till be running
	}

	//thread was asked to stop, do cleanup here
	//todo: what with still running uploads?

	close(listenFD);
	std::cout << "UploadManager stopped" << std::endl;
}
예제 #10
0
//public slots
void ChatServer::startServer()
{
    if(!bActive)
    {
        Server = new QTcpServer(this);
        if(Server->listen(QHostAddress::AnyIPv6, iPort))
        {
            connect(Server, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
            bActive = true;
            QString sMessage = tr("Server gestartet, höre auf Port %0.").arg(iPort);
            emit newLog(sMessage);
        }
    }
}
예제 #11
0
QT_BEGIN_NAMESPACE

// ### review

QDesignerServer::QDesignerServer(QObject *parent)
    : QObject(parent)
{
    m_socket = 0;
    m_server = new QTcpServer(this);
    m_server->listen(QHostAddress::LocalHost, 0);
    if (m_server->isListening())
    {
        connect(m_server, SIGNAL(newConnection()),
                this, SLOT(handleNewConnection()));
    }
}
예제 #12
0
HttpSocket::HttpSocket(const QString &iface, quint16 port)
    : QTcpServer(nullptr)
    , cfgInterface(iface)
    , terminated(false)
{
    if (!openPort(port)) {
        openPort(0);
    }

    DBUG << isListening() << serverPort();

    connect(MPDConnection::self(), SIGNAL(socketAddress(QString)), this, SLOT(mpdAddress(QString)));
    connect(MPDConnection::self(), SIGNAL(cantataStreams(QList<Song>,bool)), this, SLOT(cantataStreams(QList<Song>,bool)));
    connect(MPDConnection::self(), SIGNAL(cantataStreams(QStringList)), this, SLOT(cantataStreams(QStringList)));
    connect(MPDConnection::self(), SIGNAL(removedIds(QSet<qint32>)), this, SLOT(removedIds(QSet<qint32>)));
    connect(this, SIGNAL(newConnection()), SLOT(handleNewConnection()));
}
예제 #13
0
파일: server.cpp 프로젝트: sriks/angel
Server::Server(QWidget *parent)
:   QDialog(parent), tcpServer(0), networkSession(0),
    mInternalSync(false)
{
    statusLabel = new QLabel;
    quitButton = new QPushButton(tr("Quit"));
    quitButton->setAutoDefault(false);
    mCurrentTrackName.clear();
    mProcess = new QProcess(this);
    mXmlQuery = new QXmlQuery;
    mCurrentRequest.clear();
    connect(mProcess,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(processFinished(int,QProcess::ExitStatus)));

// Populate command filename depending on the underlying platform
    QString commandsFileName;
#ifdef Q_OS_LINUX
    commandsFileName = ":/xml/linux_commands.xml";
    // TODO: Add support to get the player name dynamically
    mPlayerName = KRhythmbox;
#else Q_OS_WIN32
    commandsFileName = ":/xml/win_commands.xml";
    mPlayerName = KWinamp;
#endif

    mCommands = new QFile(commandsFileName,this);
    if(!mCommands->open(QIODevice::ReadOnly))
    {

    }

    openSession();
    connect(quitButton, SIGNAL(clicked()), this, SLOT(close()));
    connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));

    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("Angel Server"));
}
예제 #14
0
int AccessorApp::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QMainWindow::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: wantsToExit(); break;
        case 1: handleNewConnection(); break;
        case 2: handleStartAction(); break;
        case 3: saveImageLabelSize(); break;
        case 4: handleStopAction(); break;
        case 5: showPixmap(); break;
        case 6: handleExitAction(); break;
        case 7: displayAboutBox(); break;
        default: ;
        }
        _id -= 8;
    }
    return _id;
}
예제 #15
0
void NfcPeerToPeer::initAndStartNfc()
{
    qDebug(__PRETTY_FUNCTION__);
    if (!m_appSettings) {
        return;
    }

    // Create the NFC server which will listen for incoming connections
    // (for connection-oriented only, connectionless will bind the client
    // socket to the port).
    if (!m_useConnectionLess && m_connectServerSocket) {
        qDebug() << "Creating LLCP server";
        m_nfcServer = new QLlcpServer(this);
        connect(m_nfcServer, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));

        qDebug() << "Starting to listen to " << m_nfcUri;
        m_nfcServer->listen(m_nfcUri);
    }

    // The NFC client socket
    initClientSocket();
}
예제 #16
0
void handleNewConnection(boost::asio::io_service& ioService, std::shared_ptr<ip::tcp::acceptor> acceptor)
{
	static uint16_t socketID = 1;

	std::shared_ptr<ip::tcp::socket> socket = std::make_shared<ip::tcp::socket>(ioService);
	std::shared_ptr<ip::tcp::endpoint> endpoint = std::make_shared<ip::tcp::endpoint>();
	acceptor->async_accept(*socket, *endpoint,
		[&ioService, acceptor, endpoint, socket]
		(const boost::system::error_code& error)
		{
			if (!error)
			{
				std::cout << "Received connection from: " << *endpoint;
				std::cout << " on thread id: ";
				std::cout << std::this_thread::get_id() << std::endl;

				//
				// With the connection made, start listening for messages over the socket
				handleNextMessage(socket, socketID);
				socketID++;
			}
			handleNewConnection(ioService, acceptor);
		});
}
예제 #17
0
MyServer::MyServer(QObject *parent)
    : QObject(parent)
{
    connect(&tcpServer, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
    bool listening = tcpServer.listen(QHostAddress(QHostAddress::LocalHost), 4000);
}
예제 #18
0
IntProcServer::IntProcServer()
{
    clientConnection=NULL;
    connect(this, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
}
예제 #19
0
QtTcpServerHandler::QtTcpServerHandler(WebSocketServer* webSocketServer)
: m_webSocketServer(webSocketServer)
{
    connect(&m_serverSocket, SIGNAL(newConnection()), SLOT(handleNewConnection()));
}
PGE_TcpServer::PGE_TcpServer()
{
    connect(this, SIGNAL(newConnection()), this, SLOT(handleNewConnection()));
}