Example #1
0
void Widget::on_pushButton_2_clicked()
{
    QString ipAddress = "127.0.0.1";
    int port = 8010;

    if(!status)
    {
        tcpSocket = new QTcpSocket(this);
        connect(tcpSocket, SIGNAL(connected()),
        this, SLOT(tcpConnected()));
        connect(tcpSocket, SIGNAL(disconnected()),
        this, SLOT(tcpDisconnected()));
        connect(tcpSocket, SIGNAL(readyRead()),
        this, SLOT(dataReceived()));
        tcpSocket->connectToHost(ipAddress, port);
        status = true;
    }
    else
    {
        int length = 0;
        QString message = userName + tr(":Leave Chat Room");
        length = tcpSocket->write(message.toLatin1(), message.length());

        if(length != message.length())
        {
            return;
        }

        tcpSocket->disconnectFromHost();
        status = false;
    }
}
void RFIDMonitorDaemon::tcpHandleError(QAbstractSocket::SocketError error )
{
    if(error == QAbstractSocket::ConnectionRefusedError){
        tcpDisconnected();
        return;
    }

    qDebug() <<  QString("Error: %1 - %2").arg(m_tcpSocket->error()).arg(m_tcpSocket->errorString());
}
Example #3
0
void MainDialog::initSocket()
{
    int port = 8286;
    tcpSocket = new QTcpSocket(this);
    connect(tcpSocket, SIGNAL(connected()),
    this, SLOT(tcpConnected()));
    connect(tcpSocket, SIGNAL(disconnected()),
    this, SLOT(tcpDisconnected()));
    connect(tcpSocket, SIGNAL(readyRead()),
    this, SLOT(dataReceived()));
    tcpSocket-> connectToHost (ipAddr, port);
}
RFIDMonitorDaemon::RFIDMonitorDaemon(QObject *parent) :
    QObject(parent),
    m_localServer(0),
    m_tcpSocket(0),
    m_tcpAppSocket(0),
    isConnected(false)
{
    m_configManager = new ConfigManager(this);

    m_localServer = new QLocalServer(this);
    m_tcpSocket = new QTcpSocket(this);
    m_tcpSocket->setObjectName("server");

    m_udpSocket = new QUdpSocket(this);
    m_tcpAppSocket = new QTcpSocket(this);
    m_tcpAppSocket->setObjectName("deskApp");

    m_serverName = "RFIDMonitorDaemon";

    m_restoreTimer.setInterval(10000);
    connect(&m_restoreTimer, &QTimer::timeout, [=](){
        m_configManager->restoreConfig();
        initMonitor();
    });

    connect(m_localServer, SIGNAL(newConnection()), SLOT(ipcNewConnection()));

    connect(m_tcpSocket, SIGNAL(connected()), SLOT(tcpConnected()));
    connect(m_tcpSocket, SIGNAL(disconnected()), SLOT(tcpDisconnected()));
    connect(m_tcpSocket, SIGNAL(readyRead()), SLOT(routeTcpMessage()));
    connect(m_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(tcpHandleError(QAbstractSocket::SocketError)));

    connect(m_udpSocket, SIGNAL(readyRead()), SLOT(readDatagrams()));

    connect(m_tcpAppSocket, &QTcpSocket::connected, ([=] () { m_udpSocket->close(); qDebug() <<  "Connected with DeskApp";}));
    connect(m_tcpAppSocket, &QTcpSocket::disconnected,
            ([=] () {
        qDebug() <<  "DeskApp Connection Closed";
        if(!m_udpSocket->bind(QHostAddress::Any, 9999)){
            qDebug() <<  QString("Couldn't listening broadcast");
        };
    }));

    connect(m_tcpAppSocket, SIGNAL(readyRead()), SLOT(routeTcpMessage()));

    QString socketFile = QString("/tmp/%1").arg(m_serverName);

    if(QFile::exists(socketFile)){
        QString rmCommand = QString("rm -f %1").arg(socketFile);
        system(rmCommand.toStdString().c_str());
    }
}
Example #5
0
OpenNIC::OpenNIC(QWidget *parent)
: inherited(parent)
, mActionSettings(NULL)
, mActionAbout(NULL)
, mActionQuit(NULL)
, mTrayIcon(NULL)
, mTrayIconMenu(NULL)
, ui(new Ui::OpenNICSettings)
, mRefreshTimer(0)
, mPacketState(0)
, mPacketLength(0)
, mTcpListenPort(0)
, mInitialized(false)
, mBalloonIcon(QSystemTrayIcon::Information)
, mActiveState(false)
, mScoreRulesTextChanged(false)
{
	ui->setupUi(this);
	createActions();
	createTrayIcon();
	QObject::connect(this,SIGNAL(accepted()),this,SLOT(writeSettings()));
	mTcpSocket.close();
	mBalloonStatus = tr("Initializing...");
	mRefreshTimer = startTimer(DEFAULT_REFRESH);
	mLocalNet = new OpenNICNet(&mTcpSocket);
	QObject::connect(mLocalNet,SIGNAL(dataReady(OpenNICNet*)),this,SLOT(dataReady(OpenNICNet*)));
	QObject::connect(&mTcpSocket,SIGNAL(connected()),this,SLOT(tcpConnected()));
	QObject::connect(&mTcpSocket,SIGNAL(disconnected()),this,SLOT(tcpDisconnected()));
	QObject::connect(&mTcpSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(tcpError(QAbstractSocket::SocketError)));
	QObject::connect(&mTcpSocket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(tcpStateChanged(QAbstractSocket::SocketState)));
	QObject::connect(&mTcpSocket,SIGNAL(hostFound()),this,SLOT(tcpHostFound()));
	QObject::connect(this,SIGNAL(accepted()),this,SLOT(update()));
	QObject::connect(ui->saveT1List,SIGNAL(clicked()),this,SLOT(updateT1List()));
	QObject::connect(ui->buttonBox,SIGNAL(clicked(QAbstractButton*)),this,SLOT(clicked(QAbstractButton*)));
	QObject::connect(ui->refreshNow,SIGNAL(clicked()),this,SLOT(updateDNS()));
	QObject::connect(ui->tabs,SIGNAL(currentChanged(int)),this,SLOT(tabChanged(int)));
	QObject::connect(ui->saveDomains,SIGNAL(clicked()),this,SLOT(updateDomains()));
	QObject::connect(ui->resolverPoolTable,SIGNAL(cellClicked(int,int)),this,SLOT(cellClicked(int,int)));
	QObject::connect(ui->resolverPoolTable,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(cellDoubleClicked(int,int)));
	QObject::connect(ui->scoreRuleEditor,SIGNAL(textChanged()),this,SLOT(scoreRuleEditorTextChanged()));
	setDisabledState();
}