void CClientComWorker::run()
{
	MYLOG4CPP_DEBUG<<"CClientComWorker::run() begin";

	{
		QMutexLocker lock(&m_mutex_SocketW);
		m_pSocketHandle = new QTcpSocket();
		m_pSocketInfo = new CSocketInfo();
	}
	//
	QObject::connect(m_pSocketHandle, SIGNAL(connected()), this, SLOT(slotConnected()), Qt::AutoConnection);
	QObject::connect(m_pSocketHandle, SIGNAL(disconnected()), this, SLOT(slotDisconnected()), Qt::AutoConnection);
	QObject::connect(m_pSocketHandle, SIGNAL(readyRead()), this, SLOT(slotReadyRead()), Qt::AutoConnection);//Qt::AutoConnection Qt::BlockingQueuedConnection
	QObject::connect(m_pSocketHandle, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError)), Qt::AutoConnection);

	m_WorkerState = WORK_STATE_BEGIN;
	m_WorkerState = WORK_STATE_WORKING;

	//slotConnectToServer();
	MYLOG4CPP_DEBUG<<" "<<"m_strID="<<m_pSocketInfo->m_strID
		<<" "<<"class:"<<" "<<"CClientComWorker"
		<<" "<<"fun:"<<" "<<"run"
		<<" "<<"emit signalDisconnected()"
		<<" "<<"param:"<<" "<<"m_nHandle="<<m_nHandle;

	emit signalDisconnected(m_nHandle);

	MYLOG4CPP_DEBUG<<"CClientComWorker::run() exec() begin";

	//QThread::exec() waits until QThread::exit() called
	exec();

	MYLOG4CPP_DEBUG<<"CClientComWorker::run() exec() end";


	//
	QObject::disconnect(m_pSocketHandle, SIGNAL(connected()), this, SLOT(slotConnected()));
	QObject::disconnect(m_pSocketHandle, SIGNAL(disconnected()), this, SLOT(slotDisconnected()));
	QObject::disconnect(m_pSocketHandle, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
	QObject::disconnect(m_pSocketHandle, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError)));

	{
		QMutexLocker lock(&m_mutex_SocketW);
		if (NULL != m_pSocketHandle)
		{
			//m_pSocketHandle->waitForDisconnected();
			m_pSocketHandle->close();
			delete m_pSocketHandle;
			m_pSocketHandle = NULL;
		}
		if (NULL != m_pSocketInfo)
		{
			delete m_pSocketInfo;
			m_pSocketInfo = NULL;
		}
	}
	m_WorkerState = WORK_STATE_END;
	MYLOG4CPP_DEBUG<<"CClientComWorker::run() end";
}
TcpClientSocket::TcpClientSocket(QObject *parent,int port)
{
    connect(this,SIGNAL(readyRead()),this,SLOT(dataReceived()));
//    connect(this,SIGNAL(sendtoall(QString)),this,SLOT(dataReceived(QString)));
    connect(this,SIGNAL(disconnected()),this,SLOT(slotDisconnected()));
    isfirst=port;
}
Exemple #3
0
void CProxy::slotNewConnection()
{
    QTcpSocket * h;
    while ( h = nextPendingConnection() )
    {
        QLOG_INFO() << "new pending connection";
        connect( h, SIGNAL(readyRead()),    this, SLOT(slotHostDataAvailable()) );
        connect( h, SIGNAL(disconnected()), this, SLOT(slotDisconnected()) );
        QTcpSocket * c = new QTcpSocket( this );
        connect( c, SIGNAL(readyRead()), this, SLOT(slotClientDataAvailable()) );
        connect( c, SIGNAL(disconnected()), this, SLOT(slotDisconnected()) );
        c->connectToHost( m_clientHost, m_clientPort );
        m_hostKey.insert( h, c );
        m_clientKey.insert( c, h );
    }
}
Referee::Referee(int teamID, QObject *parent) :
	QObject(parent), messengerOfTheGods(new Hermes(this)), wLimit(1024), myTeamID(teamID), messageSize(0), connection(
			false), testMode(false), verbose(true), ready(false)
{
	connect(messengerOfTheGods, SIGNAL(readyRead()), this, SLOT(slotRead()));
	connect(messengerOfTheGods, SIGNAL(connected()), this, SLOT(slotConnected()));
	connect(messengerOfTheGods, SIGNAL(disconnected()), this, SLOT(slotDisconnected()));
}
void dazeus::Server::connectToServer()
{
	printf("Connecting to server: %s\n", toString(this).c_str());
	assert( !config_->network->nickName.length() == 0 );

	irc_callbacks_t callbacks;
	memset(&callbacks, 0, sizeof(irc_callbacks_t));
	callbacks.event_connect = irc_callback;
	callbacks.event_nick = irc_callback;
	callbacks.event_quit = irc_callback;
	callbacks.event_join = irc_callback;
	callbacks.event_part = irc_callback;
	callbacks.event_mode = irc_callback;
	callbacks.event_umode = irc_callback;
	callbacks.event_topic = irc_callback;
	callbacks.event_kick = irc_callback;
	callbacks.event_channel = irc_callback;
#if LIBIRC_VERSION_HIGH > 1 || LIBIRC_VERSION_LOW >= 6
	callbacks.event_channel_notice = irc_callback;
#endif
	callbacks.event_privmsg = irc_callback;
	callbacks.event_notice = irc_callback;
	callbacks.event_invite = irc_callback;
	callbacks.event_ctcp_req = irc_callback;
	callbacks.event_ctcp_rep = irc_callback;
	callbacks.event_ctcp_action = irc_callback;
	callbacks.event_unknown = irc_callback;
	callbacks.event_numeric = irc_eventcode_callback;

	irc_ = (void*)irc_create_session(&callbacks);
	if(!irc_) {
		std::cerr << "Couldn't create IRC session in Server.";
		abort();
	}
	irc_set_ctx(IRC, this);

	assert( config_->network->nickName.length() != 0 );
	std::string host = config_->host;
	if(config_->ssl) {
#if defined(LIBIRC_OPTION_SSL_NO_VERIFY)
		host = "#" + host;
		if(!config_->ssl_verify) {
			std::cerr << "Warning: connecting without SSL certificate verification." << std::endl;
			irc_option_set(IRC, LIBIRC_OPTION_SSL_NO_VERIFY);
		}
#else
		std::cerr << "Error: Your version of libircclient does not support SSL. Failing connection." << std::endl;
		slotDisconnected();
		return;
#endif
	}
	irc_connect(IRC, host.c_str(),
		config_->port,
		config_->network->password.c_str(),
		config_->network->nickName.c_str(),
		config_->network->userName.c_str(),
		config_->network->fullName.c_str());
}
Exemple #6
0
void Server::incomingConnection(qintptr handle)
{
    TcpClientSocket *client = new TcpClientSocket(this);
    client->setSocketDescriptor(handle);

    connect(client, SIGNAL(signalMsg(qintptr)), this, SLOT(slotReadMsg(qintptr)));
    connect(client, SIGNAL(signalDisconnected(qintptr, QString)), this, SLOT(slotDisconnected(qintptr, QString)));

    clientList.insert(handle, client);
}
Exemple #7
0
void WidgetRdpView::slotDisconnected()
{
  connectionEstablished_ = false;
  onDisconnecting_ = false;

  retryCount_++;

  if (freeRDPwidget_)
  {
    disconnect(freeRDPwidget_,
            SIGNAL(disconnected()),
            this,
            SLOT(slotDisconnected()));

    loGrid_->removeWidget(freeRDPwidget_);
    delete (freeRDPwidget_);
    freeRDPwidget_ = 0;
  }

  if (inErrorMode_)
    return;

  // we want to reconnect
  ILOG("reconnect: create a new rdp widget");

  #ifndef SKIP_FREERDP_CODE
    freeRDPwidget_ = new RemoteDisplayWidget();
  #else
    freeRDPwidget_ = new QLabel();
    freeRDPwidget_->setText("FreeRDP disabled in this build");
  #endif

  loGrid_->addWidget(freeRDPwidget_, 0, 0, 1, 1);

  connect(freeRDPwidget_,
          SIGNAL(disconnected()),
          this,
          SLOT(slotDisconnected()));

  ILOG("WidgetRdpView: we start a very short timer to call resizeVmDesktopAndConnectViaRdp() in 10ms");
  timerResizeHappend_.start(10);
}
Widget::Widget( QWidget * parent )
	: QWidget( parent )
{
	createWidgets();

	setWindowTitle( tr("Echo client %1").arg( PORT ) );

	connect( &socket, SIGNAL( connected() ), SLOT( slotConnected() ) );
	connect( &socket, SIGNAL( disconnected() ), SLOT( slotDisconnected() ) );
	connect( &socket, SIGNAL( readyRead() ), SLOT( slotRead() ) );

	tcpConnect();
}
Exemple #9
0
void my_server::slotNewConnection()
{
    QTcpSocket* pClientSocket = m_ptcpServer->nextPendingConnection();
    int id_user_socket = pClientSocket->socketDescriptor();
    map_clients[id_user_socket]  = new client(pClientSocket);

    connect(pClientSocket, SIGNAL(disconnected()), this, SLOT(slotDisconnected()));
    connect(pClientSocket, SIGNAL(readyRead()), this, SLOT(slotReadClient()));

    map_clients[id_user_socket]->sendToClient("123456789");
    emit map_to_combo_box(this->map_clients);
    emit text_to_console("Client connected!");

}
/// \cond
void QXmppBookmarkManager::setClient(QXmppClient *client)
{
    bool check;
    Q_UNUSED(check);

    QXmppClientExtension::setClient(client);

    check = connect(client, SIGNAL(connected()),
                    this, SLOT(slotConnected()));
    Q_ASSERT(check);

    check = connect(client, SIGNAL(disconnected()),
                    this, SLOT(slotDisconnected()));
    Q_ASSERT(check);
}
int TcpClientSocket::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QTcpSocket::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: updateClients((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 1: disconnected((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 2: dataReceived(); break;
        case 3: slotDisconnected(); break;
        default: ;
        }
        _id -= 4;
    }
    return _id;
}
Exemple #12
0
void TcpClient::slotEnter()
{
	if (!status)
	{
		QString ip = serverIPLineEdit->text();
		if (!serverIP->setAddress(ip))
		{
			QMessageBox::information(this, tr("error"), tr("server ip address error!"));
			return;
		}

		if (userNameLineEdit->text() == "")
		{
			QMessageBox::information(this, tr("error"), tr("User name error!"));
			return;
		}

		userName = userNameLineEdit->text();

		tcpSocket = new QTcpSocket(this);
		connect(tcpSocket, SIGNAL(connected()), this, SLOT(slotConnected()));
		connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(slotDisconnected()));
		connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(dataReceived()));

		tcpSocket->connectToHost(*serverIP, port);

		status = true;
	}
	else
	{
		int length = 0;
		QString msg = userName + tr(":Leave Chat Room");
		if ((length = tcpSocket->write(msg.toLatin1(), msg.length())) != msg.length())
		{
			return;
		}

		tcpSocket->disconnectFromHost();

		status = false;
	}
}
void CDistributeTaskWorker::run()
{
	MYLOG4CPP_DEBUG<<"CStockTcpClientActor::run()";

	m_pComWorker = new CClientComWorker(m_strServerIP, m_nServerPort, this);
	QObject::connect(m_pComWorker, SIGNAL(signalDisconnected()), this, SLOT(slotDisconnected()), Qt::AutoConnection);
	QObject::connect(m_pComWorker, SIGNAL(signalConnected()), this, SLOT(slotConnected()), Qt::AutoConnection);
	QObject::connect(this, SIGNAL(signalConnectToServer()), m_pComWorker, SLOT(slotConnectToServer()), Qt::AutoConnection);

	//
	m_pMessageManager = new CMessageManager(this);
	QObject::connect(m_pComWorker, SIGNAL(signalProcessMessage(QByteArray*)), m_pMessageManager, SLOT(slotProcessMessage(QByteArray*)), Qt::AutoConnection);
	QObject::connect(m_pMessageManager, SIGNAL(signalWriteMessage(QByteArray*)), m_pComWorker, SLOT(slotWriteMessage(QByteArray*)), Qt::AutoConnection);

	m_pComWorker->start();

	m_WorkerState = WORK_STATE_BEGIN;
	m_WorkerState = WORK_STATE_WORKING;

	//QThread::exec() waits until QThread::exit() called
	exec();


	if (NULL != m_pComWorker)
	{
		m_pComWorker->terminateAndWait();
		delete m_pComWorker;
		m_pComWorker = NULL;
	}

	if (NULL != m_pMessageManager)
	{
		delete m_pMessageManager;
		m_pMessageManager = NULL;
	}

	m_WorkerState = WORK_STATE_END;

}
IVEFStreamHandler::IVEFStreamHandler(ivef::Parser *parser) {

    // clear user/password
    m_user = "******";
    m_password = "******";
    m_log = NULL;
    m_parser = parser;
    m_slipstream = false;
    m_statistics = false;
    m_bytesIn = 0;
    m_bytesOut = 0;

    // create a new socket
    m_tcpSocket = new QTcpSocket(this);

    connect(m_tcpSocket, SIGNAL(connected()),
            this, SLOT(slotConnected()));
    connect(m_tcpSocket, SIGNAL(disconnected()),
            this, SLOT(slotDisconnected()));
    connect(m_tcpSocket, SIGNAL(readyRead()),
            this, SLOT(slotReadyRead()));
    connect(m_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
            this, SLOT(displayError(QAbstractSocket::SocketError)));
}
Exemple #15
0
MainWnd::MainWnd( QWidget * parent )
: QMainWindow( parent )
{
    ui.setupUi( this );
    connect( this, SIGNAL(sigLog(const QString &)), this, SLOT(slotLog(const QString &)), Qt::QueuedConnection );
    connect( ui.console, SIGNAL(line_validate(const QString &)), this, SLOT(slotSend(const QString &)), Qt::QueuedConnection );

    QObject::connect( ui.clearLog,    SIGNAL(triggered()), this, SLOT(slotClearLog()) );
    QObject::connect( ui.dontSleep,   SIGNAL(triggered()), this, SLOT(slotDontSleep()) );

    QObject::connect( ui.showFullLog, SIGNAL(triggered()), this, SLOT(slotShowFullLog()) );
    QObject::connect( ui.queryStatus, SIGNAL(triggered()), this, SLOT(slotStatus()) );
    QObject::connect( ui.queryOsc,    SIGNAL(triggered()), this, SLOT(slotOsc()) );
    QObject::connect( ui.shutdown,    SIGNAL(triggered()), this, SLOT(slotShutdown()) );
    QObject::connect( ui.setupPipe,   SIGNAL(triggered()), this, SLOT(slotSetupPipe()) );

    QObject::connect( ui.lightBtn,    SIGNAL(clicked()),   this, SLOT(slotLight()) );
    QObject::connect( ui.motoEnBtn,   SIGNAL(clicked()),   this, SLOT(slotMotoEn()) );

    QObject::connect( ui.fwdBtn,      SIGNAL(pressed()),   this, SLOT(slotForward()) );
    QObject::connect( ui.bwdBtn,      SIGNAL(pressed()),   this, SLOT(slotBackward()) );
    QObject::connect( ui.leftBtn,     SIGNAL(pressed()),   this, SLOT(slotLeft()) );
    QObject::connect( ui.rightBtn,    SIGNAL(pressed()),   this, SLOT(slotRight()) );

    QObject::connect( ui.fwdBtn,      SIGNAL(released()),  this, SLOT(slotStop()) );
    QObject::connect( ui.bwdBtn,      SIGNAL(released()),  this, SLOT(slotStop()) );
    QObject::connect( ui.leftBtn,     SIGNAL(released()),  this, SLOT(slotStop()) );
    QObject::connect( ui.rightBtn,    SIGNAL(released()),  this, SLOT(slotStop()) );


    QObject::connect( ui.showFullLog, SIGNAL(triggered()), this, SLOT(slotShowFullLog()) );

    m_peer = new QXmppPeer( this );
    QObject::connect( m_peer, SIGNAL(connected()),      this, SLOT(slotConnected()) );
    QObject::connect( m_peer, SIGNAL(disconnected()),   this, SLOT(slotDisconnected()) );
    QObject::connect( m_peer, SIGNAL(textmsg(QString)), this, SLOT(qxmppMessageReceived(QString)) );

    m_video = new QXmppVideo( m_peer );
    // It also connects frameReady() signal to an appropriate slot.
    ui.view->setVideo( m_video );
    this->setCentralWidget( ui.view );

    QSettings ini( CONFIG_FILE, QSettings::IniFormat );
    ini.beginGroup( "main" );
    QString selfJid  = ini.value( "selfJid",    "client@xmpp" ).toString();
    QString destJid  = ini.value( "destJid",    "host@xmpp" ).toString();
    QString password = ini.value( "password",   "12345" ).toString();
    QString host     = ini.value( "host",       QString() ).toString();
    int     port     = ini.value( "port",       -1 ).toInt();
    bool    tls      = ini.value( "tls",        true ).toBool();
    bool updateDest  = ini.value( "updateDest", true ).toBool();

    m_peer->setTarget( destJid, updateDest );
    m_video->setTarget( destJid );
    m_peer->connect( selfJid, password, host, port, tls );
    m_jidDest = destJid;

    m_pipe = new QXmppMsgPipe( m_peer, 1 );
    m_pipe->setOutPipe( m_jidDest, 1234, 22, "localhost" );

    m_dontSleepTimer = new QTimer( this );
    m_dontSleepTimer->setInterval( 15000 );
    QObject::connect( m_dontSleepTimer, SIGNAL(timeout()), 
                      this,             SLOT(slotDontSleepTimeout()) );
}
TcpClientSocket::TcpClientSocket(QObject *parent)
{
    connect(this, SIGNAL(readyRead()), this, SLOT(dataReceived()));
    connect(this, SIGNAL(disconnected()), this, SLOT(slotDisconnected()));
}
Exemple #17
0
WidgetRdpView::WidgetRdpView( QString parHost, PMInstance* pmInstance )
{
  host_ = parHost;
  pmInstance_ = pmInstance;
  rdpPort_ = pmInstance_->getConfig()->rdpPort;
  sshPort_ = pmInstance_->getConfig()->sshPort;
  subtractDisplayWidthMin_ = pmInstance_->getConfig()->subtractDisplayWidth;
  subtractDisplayHeightMin_ = pmInstance_->getConfig()->subtractDisplayHeight;
  connectionEstablished_ = false;
  onDisconnecting_ = false;
  retryCount_ = 0;
  inErrorMode_ = false;
  lblErrorMessage_ = new QLabel();

  name_ = pmInstance_->getConfig()->name;
  subtractDisplayWidthCurrent_ = subtractDisplayWidthMin_;
  subtractDisplayHeightCurrent_ = subtractDisplayHeightMin_;

  setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
  
  QPalette palette( this->palette() );
  palette.setColor( QPalette::Background, pmInstance_->getConfig()->color );
  this->setAutoFillBackground( true );
  this->setPalette( palette );

  loGrid_ = new QGridLayout();
  loGrid_->setSpacing(0);
  loGrid_->setMargin(0);
  loGrid_->setColumnStretch(0,0);
  loGrid_->setRowStretch(0,0);
  loGrid_->setSizeConstraint( QLayout::SetNoConstraint );



  #ifndef SKIP_FREERDP_CODE
    freeRDPwidget_ = new RemoteDisplayWidget();
  #else
    freeRDPwidget_ = new QLabel();
    freeRDPwidget_->setText("FreeRDP disabled in this build");
    freeRDPwidget_->show();
  #endif
  screenHeight_ = freeRDPwidget_->height();
  screenWidth_ = freeRDPwidget_->width();
  
  QPalette paletteRdp = freeRDPwidget_->palette();
  paletteRdp.setColor( this->backgroundRole(), Qt::red );
  freeRDPwidget_->setPalette( paletteRdp );


  // The FreeRDPWidget seems not to understand Qt:AlignCenter.
  // We implement a similar behaviour by aligning it top-left, and adding margins to the layout manager.
  loGrid_->setContentsMargins( subtractDisplayWidthMin_ / 2, subtractDisplayHeightMin_ / 2, 0, 0 );
  loGrid_->addWidget(freeRDPwidget_, 0, 0, 0, 0 );
  setLayout(loGrid_);

  connect(freeRDPwidget_,
          SIGNAL(disconnected()),
          this,
          SLOT(slotDisconnected()));

  timerResizeHappend_.setSingleShot(true);
  connect(&timerResizeHappend_,
          SIGNAL(timeout()),
          this,
          SLOT(slotTimerResizeHappendFired()));
}