Example #1
0
void ConnectionController::connectToServer()
{
	bool reconnect=1;
        m_pSocket= new QTcpSocket(this); // <-- needs to be a member variable: QTcm_pSocket* _pSocket;

	connect(this,SIGNAL(appendSensorsToTable(QVector<Sensor*>)),m_sensorsTableModel,SLOT(onAddSensorsToTable(QVector<Sensor*>)));
	connect( m_pSocket, SIGNAL(readyRead()), SLOT(readTcpData()) );

	while(reconnect)
	{
		m_pSocket->connectToHost("127.1.1.1", 1666); // Server returns: "Sensor:"
		if( m_pSocket->waitForConnected(SERVER_RECONNECT_TIME) )
		{
			//introduceMyself();
			m_pSocket->write(SERVER_CMD_MY_NAME);
			reconnect=0;
		}
		else
			{
				if( QMessageBox::information(0,"Server error",
											 "Cannot connect to server. Retry?",
											 QMessageBox::Yes|QMessageBox::No) == QMessageBox::No)
					reconnect=0;
			}
	}
}
Example #2
0
AIDebugger::AIDebugger(AINodeStaticResolver& resolver) :
		QObject(), _stateHandler(new StateHandler(*this)), _characterHandler(new CharacterHandler(*this)), _characterStaticHandler(
				new CharacterStaticHandler(*this)), _pauseHandler(new PauseHandler(*this)), _namesHandler(new NamesHandler(*this)), _nopHandler(
				new NopHandler()), _selectedId(-1), _socket(this), _pause(false), _resolver(resolver) {
	connect(&_socket, SIGNAL(readyRead()), SLOT(readTcpData()));
	connect(&_socket, SIGNAL(disconnected()), SLOT(onDisconnect()));

	ai::ProtocolHandlerRegistry& r = ai::ProtocolHandlerRegistry::get();
	r.registerHandler(ai::PROTO_STATE, _stateHandler);
	r.registerHandler(ai::PROTO_CHARACTER_DETAILS, _characterHandler);
	r.registerHandler(ai::PROTO_CHARACTER_STATIC, _characterStaticHandler);
	r.registerHandler(ai::PROTO_PAUSE, _pauseHandler);
	r.registerHandler(ai::PROTO_NAMES, _namesHandler);
	r.registerHandler(ai::PROTO_PING, _nopHandler);
}
TCPClientController::TCPClientController(QObject *parent,QString ip, quint16 port) : QObject(parent)
{
    //image = 0;
    QByteArray data; // <-- fill with data

    _pSocket = new QTcpSocket( this ); // <-- needs to be a member variable: QTcpSocket * _pSocket;
    //connect(_pSocket, SIGNAL(readyRead()),this, SLOT(readyRead()));
    connect( _pSocket, SIGNAL(readyRead()), SLOT(readTcpData()) );


    _pSocket->connectToHost(ip, port);
    if( _pSocket->waitForConnected() ) {
        //_pSocket->write( data );
    }
}
Example #4
0
// Function using to connect with server
void MainWindow::connectToServer(QString address, int port)
{
    qDebug() << "Connecting to server: " << address << ":" << port;

    connectionManager->connectToHost(address, port);
    connect(connectionManager, SIGNAL(readyRead()), SLOT(readTcpData()));

    connect(connectionManager, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(checkConnection(QAbstractSocket::SocketState)));

    if(connectionManager->waitForConnected(500)) {
        qDebug() << "Connected!";
    }else {
        qDebug() << "Timeout waiting for connection";
        QMessageBox::critical(this, "Problem during connection to server", "Server can't be reach at this time, sorry");
    }

    checkConnection(connectionManager->state());

}
MainWindowLifeGame::MainWindowLifeGame(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindowLifeGame)
{
/*
export DISPLAY=":0.0"
xhost +
cd Desktop/ISIB_LifeGameClientV1/
sudo DISPLAY=:0 ./ISIB_LifeGameClient
*/
    this->rpiGpio = new mmapGpio();
    this->rpiGpio->setPinDir(this->pinNumIn,mmapGpio::INPUT);

   this->tnbr = new QRegExp ("Tree ([0-9]+)");
   this->herbr = new QRegExp ("Herbi ([0-9]+)");
   this->carbr  = new QRegExp ("Carni ([0-9]+)");
   this->invbr  = new QRegExp ("Invad ([0-9]+)");
   this->yearBr  = new QRegExp ("YEAR ([0-9]+)");


    int id = QFontDatabase::addApplicationFont("://data/Greenscr.ttf");
    QString family = QFontDatabase::applicationFontFamilies(id).at(0);
    QFont Greenscr(family,18);

    this->socket = new QTcpSocket(this);
    this->connect(this->socket, SIGNAL(readyRead()), SLOT(readTcpData()));
    this->connect(this->socket, SIGNAL(disconnected()), SLOT(autoReconnect()));

    QSettings settings("conf.ini", QSettings::IniFormat);
    this->ip = settings.value("OPTIONS/IP","127.0.0.1").toString();
    this->port = settings.value("OPTIONS/PORT", 11900).toInt();


    //qDebug() << "Address "<<this->ip<<":"<<this->port;

    this->timerDots = new QTimer();
    this->timerDots->connect(this->timerDots, SIGNAL(timeout()),this, SLOT(updateDots()));
    this->timerDots->start(500);

    this->timerButt = new QTimer();
    this->timerButt->connect(this->timerButt, SIGNAL(timeout()),this, SLOT(changeBG()));

    this->timerGpio = new QTimer();
    this->timerGpio->connect(this->timerGpio, SIGNAL(timeout()),this, SLOT(readGPIO()));
    this->timerGpio->start(100);

    this->dataTab[0]=0;
    this->dataTab[1]=0;
    this->dataTab[2]=0;
    this->dataTab[3]=0;

    bool connected = false;
    while(!(connected)){
        this->socket->connectToHost(this->ip,this->port);
        if( this->socket->waitForConnected(5000) ) {
           this->socket->write("HELLO SERVER[/TCP]");
           this->socket->flush();
           connected = true;
        }
    }

    ui->setupUi(this);



    ui->label->setFont(Greenscr);
    ui->label->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed));
    ui->labelYear->setFont(Greenscr);
    ui->labelDotAnim->setFont(Greenscr);
    ui->labelArbre->setFont(Greenscr);
    ui->labelArbre_2->setFont(Greenscr);
    ui->labelArbre_3->setFont(Greenscr);
    ui->labelArbre_4->setFont(Greenscr);
    ui->progressBarTree->setFont(Greenscr);
    ui->progressBarHerbi->setFont(Greenscr);
    ui->progressBarCarni->setFont(Greenscr);
    ui->progressBarInvade->setFont(Greenscr);

    ui->textEditTree->setFont(Greenscr);
    ui->textEditHerbi->setFont(Greenscr);
    ui->textEditCarni->setFont(Greenscr);
    ui->textEditBrut->setFont(Greenscr);
    ui->textEditInvad->setFont(Greenscr);

    QMainWindow::showFullScreen();
    QApplication::setOverrideCursor(Qt::BlankCursor);

     /*this->sbHerbi = ui->textEditHerbi->verticalScrollBar();
     this->sbHerbi->setValue(this->sbHerbi->maximum());

     this->sbCarni = ui->textEditCarni->verticalScrollBar();
     this->sbCarni->setValue(this->sbCarni->maximum());

     this->sbBrut = ui->textEditBrut->verticalScrollBar();
     this->sbBrut->setValue(this->sbBrut->maximum());

     this->sbInvad = ui->textEditInvad->verticalScrollBar();
     this->sbInvad->setValue(this->sbInvad->maximum());

    this->sbTree = ui->textEditTree->verticalScrollBar();
    this->sbTree->setValue(this->sbTree->maximum());
*/

}