void Client::parseAdminAuth() { qDebug() << "parseAmdinAuth():"; if (this->status_ != ST_CONNECTED) { qDebug() << "cmd not allowed"; this->disconnectFromHost(); return; } if (buf_.size() < CMD1_ADM_SIZE) return; // not all data avaliable if (getAdminLogin(buf_) != "admin" || getAdminPassword(buf_) != "admin") { qDebug() << "auth failed"; this->disconnectFromHost(); return; } this->status_ = ST_ADMIN; AdminInfo* adminInfo = new AdminInfo; adminInfo->login = getAdminLogin(buf_); adminInfo->pass = getAdminPassword(buf_); this->clientInfo_.reset(adminInfo); qDebug() << "New admin authorized:"; buf_ = buf_.right(buf_.size() - CMD1_ADM_SIZE); if (buf_.size() > 0) onDataReceived(); // If something in buffer - parse again }
void kuro::AbstractOutput::dataReceptionHandler(int data) { waiting++; std::lock_guard<std::mutex> lock(dataReceptionMutex); onDataReceived(data); waiting--; }
void Twitter::requestData() { if (_loading) { return; } _loading = true; emit tweetLoadingStart(); netManager = new QNetworkAccessManager(); connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*))); if (!netManager) { //emit complete("Unable to create QNetworkAccessManager!", false); return; } QString queryUri = "http://search.twitter.com/search.json?q=%22BlackBerry10%22"; qDebug() << queryUri; QUrl url(queryUri); QNetworkRequest req(url); QNetworkReply* ipReply = netManager->get(req); connect(ipReply, SIGNAL(finished()), this, SLOT(onDataReceived())); }
void HMI_Client::onConnected() { connect(this->socket, SIGNAL(disconnected()), this, SLOT(onDisconnected())); connect(this->socket, SIGNAL(readyRead()), this, SLOT(onDataReceived())); emit connectedToServer(); socket->write(hmi->getInitPacket().encode()); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); _sensors.push_back(Sensor(SensorData('s', CUSTOM_SENSOR01, 0, 0), 25.5)); _sensors.push_back(Sensor(SensorData('s', CUSTOM_SENSOR02, 0, 0), 27.5)); _sensors.push_back(Sensor(SensorData('s', CUSTOM_SENSOR03, 0, 0), 28.5)); for (Sensor sensor: _sensors) { ui->comboBox_SensorId->addItem(QString::number(sensor.sensorData.byte01), sensor.sensorData.byte01); _sensorIds.push_back(sensor.sensorData.byte01); } _tcpClient = new TcpClient(CUSTOM_IPV4ADDRESS, CUSTOM_PORT, _sensorIds, CUSTOM_QUERYINTERVAL, this); bool isOk; // TcpClient: Connections isOk = connect(_tcpClient, SIGNAL(dataReceived(quint8, qreal)), this, SLOT(onDataReceived(quint8, qreal))); Q_ASSERT(isOk); Q_UNUSED(isOk); isOk = connect(_tcpClient, SIGNAL(dataReceived(SensorData)), this, SLOT(onDataReceived(SensorData))); Q_ASSERT(isOk); Q_UNUSED(isOk); // GUI: Connections isOk = connect(ui->pushButton_TemperatureSet, SIGNAL(clicked()), this, SLOT(setTemperatureDesired())); Q_ASSERT(isOk); Q_UNUSED(isOk); isOk = connect(ui->comboBox_SensorId, SIGNAL(currentIndexChanged(int)), this, SLOT(on_comboBox_SensorId_currentIndexChanged(int))); Q_ASSERT(isOk); Q_UNUSED(isOk); _tcpClient->start(); }
void VLongPollClient::requestData(const QString &ts) { QUrl url = m_url; url.addQueryItem("ts", ts); QNetworkRequest request(url); QNetworkReply *reply = static_cast<QNetworkAccessManager*>(m_connection)->get(request); connect(reply, SIGNAL(finished()), this, SLOT(onDataReceived())); }
Network::Network(QSettings *settings, QObject *parent) : QObject(parent), _settings(settings) { connect(&_socket, SIGNAL(readyRead()), SLOT(onDataReceived())); QHostInfo::lookupHost("pastexen.com", this, SLOT(lookedUp(QHostInfo))); }
void TcpConnection::on_data_received(TcpConnectionPtr sender, void* data, size_t length){ if(onDataReceived != NULL){ onDataReceived(sender, data, length); } else{ print_err("No onDataReceived handler!!!\n"); } }
Client::Client(QTcpSocket *socket, ClientInfoStorage *storage, QObject *parent): QObject(parent), socket_(socket), storage_(storage), clientInfo_(), status_(ST_CONNECTED) { connect(socket_,SIGNAL(readyRead()), this,SLOT(onDataReceived())); }
void Widget::init() { int port = m_settings.get("main/port").toInt(); if (!m_socket.bind(QHostAddress::Any, port)) { qCritical() << "Unable to listen port" << port; return; } connect(&m_socket, SIGNAL(readyRead()), this, SLOT(onDataReceived())); // m_shortcutGrabber.loadShortcuts(); }
void Client::parseDisconnect() { if (buf_.size() < 3) // TODO: remove magic number return; // not all data avaliable qDebug() << "parseDisconnect():"; this->disconnectFromHost(); buf_=buf_.right(buf_.size() - 3); if (buf_.size() > 0) onDataReceived(); // If something in buffer - parse again }
void Twitter::replyFinished(QNetworkReply* reply) { QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); if (!possibleRedirectUrl.toUrl().isEmpty()) { QNetworkRequest req(possibleRedirectUrl.toUrl()); qDebug("Redirected to: "); qDebug() << possibleRedirectUrl.toUrl(); QNetworkReply* ipReply = netManager->get(req); connect(ipReply, SIGNAL(finished()), this, SLOT(onDataReceived())); } }
void SimpleNetwork::send(Vehicle* sender,void* data){ vns::HashTable<uint64, Vehicle*>::Iterator it(onBoardUnits); vns::Vec pos = sender->getPosition(); while( it.isValid() ) { Vehicle* vehicle = it.value(); if(pos.distanceToLessThan(vehicle->getPosition(),communicationRange)){ onDataReceived(sender,vehicle,data); } it.next(); } onSendFinish(data); };
void Client::sendPong() { qDebug() << "Ping received!"; if (buf_.size()<3) // TODO: remove magic number return; // not all data avaliable qDebug() << "Ping parsed!"; buf_ = buf_.right(buf_.size() - 3); if (buf_.size() > 0) onDataReceived(); // If something in buffer - parse again }
test_rs232::test_rs232(QObject *parent) : QObject(parent) { /** how to use it? **/ // open com3 emit com.sigOpenComm("com3"); // send data to com3 (it is very very easy to send data to com port. emit com.sigSendDatagram("Hello RS232 \n\r"); // handle the signal from com for data received. connect(&com,SIGNAL(sigDataReceived(QByteArray)), this,SLOT(onDataReceived(QByteArray))); }
void JingleSession::setInitiated(IJingleApplication *AApplication) { FStatus=IJingle::Initiated; disconnect(parent()); setParent(AApplication->instance()); connect(this,SIGNAL(sessionInitiated(Jid,QString)),parent(),SLOT(onSessionInitiated(Jid,QString))); connect(this,SIGNAL(sessionAccepted(Jid,QString)),parent(),SLOT(onSessionAccepted(Jid,QString))); connect(this,SIGNAL(sessionConnected(Jid,QString)),parent(),SLOT(onSessionConnected(Jid,QString))); connect(this,SIGNAL(sessionTerminated(Jid,QString,IJingle::SessionStatus,IJingle::Reason)),parent(),SLOT(onSessionTerminated(Jid,QString,IJingle::SessionStatus,IJingle::Reason))); connect(this,SIGNAL(sessionInformed(QDomElement)),parent(),SLOT(onSessionInformed(QDomElement))); connect(this,SIGNAL(receivingData(Jid,QString)),parent(),SLOT(onDataReceived(Jid,QString))); connect(this,SIGNAL(actionAcknowledged(Jid,QString,IJingle::Action,IJingle::CommandRespond,IJingle::SessionStatus,Jid,IJingle::Reason)),parent(),SLOT(onActionAcknowledged(Jid,QString,IJingle::Action,IJingle::CommandRespond,IJingle::SessionStatus,Jid,IJingle::Reason))); emit sessionInitiated(FThisParty, FSid); }
int ServerExample::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: onClientConnection(); break; case 1: onDataReceived((*reinterpret_cast< QString(*)>(_a[1]))); break; case 2: onPong((*reinterpret_cast< quint64(*)>(_a[1]))); break; case 3: onClientDisconnection(); break; default: ; } _id -= 4; } return _id; }
void Client::parseTransmit() { qDebug() << "parseTransmit():"; if ( !(this->status_ == ST_ADMIN || this->status_ == ST_CLIENT)) { qDebug() << "cmd not allowed"; this->disconnectFromHost(); return; } if (buf_.size()<9) // TODO: remove magic number return; // not all data avaliable qDebug() << "buf size" << buf_.size(); qDebug() << "packet len" << getPacketLength(buf_); if (buf_.size()<getPacketLength(buf_)+9) // TODO: remove magic number return; // not all data avaliable qint16 clientId=getClientId(buf_); QByteArray cmd=getPacketData(buf_); QByteArray response; response.append(CSPYP1_PROTOCOL_ID); response.append(CSPYP1_PROTOCOL_VERSION); response.append(CMD1_TRANSMIT); response.append(toBytes(getId())); response.append(toBytes(cmd.size())); response.append(cmd); auto destClient = getServer()->searchClient(clientId); qDebug() << "Client to ID:" << clientId; if (destClient != getServer()->clientEnd()) { qDebug() << "transmiting data.."; destClient.value()->send(response); } buf_=buf_.right(buf_.size() - (getPacketLength(buf_) + 9)); if (buf_.size() > 0) onDataReceived(); // If something in buffer - parse again }
JingleSession::JingleSession(const Jid &AThisParty, const Jid &AOtherParty, const QString &AApplicationNS): QObject(FJingle->appByNS(AApplicationNS)->instance()),FValid(false), FOutgoing(true), FApplicationNamespace(AApplicationNS),FThisParty(AThisParty), FOtherParty(AOtherParty), FSid(getSid(AThisParty)), FActionId(), FAction(IJingle::NoAction), FReason(IJingle::NoReason) { FSessions[FThisParty].insert(FSid, this); if (FThisParty.isValid() && FOtherParty.isValid()) { FValid=true; connect(this,SIGNAL(sessionInitiated(Jid,QString)),parent(),SLOT(onSessionInitiated(Jid,QString))); connect(this,SIGNAL(sessionAccepted(Jid,QString)),parent(),SLOT(onSessionAccepted(Jid,QString))); connect(this,SIGNAL(sessionConnected(Jid,QString)),parent(),SLOT(onSessionConnected(Jid,QString))); connect(this,SIGNAL(sessionTerminated(Jid,QString,IJingle::SessionStatus,IJingle::Reason)),parent(),SLOT(onSessionTerminated(Jid,QString,IJingle::SessionStatus,IJingle::Reason))); connect(this,SIGNAL(sessionInformed(QDomElement)),parent(),SLOT(onSessionInformed(QDomElement))); connect(this,SIGNAL(receivingData(Jid,QString)),parent(),SLOT(onDataReceived(Jid,QString))); connect(this,SIGNAL(actionAcknowledged(Jid,QString,IJingle::Action,IJingle::CommandRespond,IJingle::SessionStatus,Jid,IJingle::Reason)),parent(),SLOT(onActionAcknowledged(Jid,QString,IJingle::Action,IJingle::CommandRespond,IJingle::SessionStatus,Jid,IJingle::Reason))); } }
void Client::parseList() { qDebug() << "parseList():"; if (this->status_!=ST_ADMIN) { qDebug() << "cmd not allowed"; this->disconnectFromHost(); return; } if (buf_.size()<3) // TODO: remove magic number return; // not all data avaliable buf_=buf_.right(buf_.size()-3); if (buf_.size()>0) onDataReceived(); // If something in buffer - parse again this->sendList(getServer()->listConnectedClients()); }
void Client::parseClientAuth() { qDebug() << "parseClientAuth():"; if (this->status_ != ST_CONNECTED) { qDebug() << "cmd not allowed"; this->disconnectFromHost(); return; } qDebug() << buf_.size(); if (buf_.size() < CMD1_AUTH_SIZE) return; // not all data avaliable this->status_ = ST_CLIENT; ClientInfo* clientInfo = new ClientInfo; clientInfo->hash = getClientHash(buf_); clientInfo->os = getClientOs(buf_); clientInfo->deviceType = getClientDevice(buf_); ClientInfoStorage::ClientInfo storeInfo; storeInfo.hash = clientInfo->hash; storeInfo.ip = QHostAddress(getIp()); // TODO: some refactor here!! storeInfo.os = clientInfo->os; // storeInfo for saving client; storeInfo.device = clientInfo->deviceType; // clientInfo - for client? mb not needed? storage_->updateClient(storeInfo); // to storage clientInfo->caption=storage_->getCaption(clientInfo->hash); this->clientInfo_.reset(clientInfo); // to self qDebug() << "new client authorized"; this->getServer()->resendListToAdmins(); buf_ = buf_.right(buf_.size() - CMD1_AUTH_SIZE); if (buf_.size() > 0) onDataReceived(); // If something in buffer - parse again }
Controller::Controller(Model *model_): model(model_), serverAddress( QHostAddress::LocalHost ), serverPort( 1234 ) { client = new QTcpSocket(this); connect(client,SIGNAL(readyRead()), this,SLOT(onDataReceived())); connect( client, SIGNAL( connected() ), this, SLOT( onConnected() ) ); connect( client, SIGNAL( error(QAbstractSocket::SocketError) ), this, SLOT( onError(QAbstractSocket::SocketError) ) ); readConfig(); }
pSocket::pSocket(QTcpSocket *socket, QThread *thread, QAtomicInt& limit) : QObject(0), _socket(socket), _packetSize(0), _limit(limit) { connect(_socket, SIGNAL(readyRead()), this, SLOT(onDataReceived())); connect(_socket, SIGNAL(disconnected()), this, SLOT(deleteLater())); // connect(_socket, SIGNAL(disconnected()), _socket, SLOT(deleteLater())); connect(this, SIGNAL(saveFile(QByteArray,QString)), pSaver::inst(), SLOT(save(QByteArray,QString))); _socket->setParent(this); moveToThread(thread); #ifdef FUNC_DEBUG qDebug() << '\n' << Q_FUNC_INFO << "New connection" << socket->localAddress(); #endif #ifdef TIME_DEBUG if (!dTime) { dTime = new QTime; dTime->start(); } #endif }
void Client::parseSetInfo() { qDebug() << "SetInfo received!"; if (this->status_!=ST_ADMIN) { qDebug() << "cmd not allowed"; this->disconnectFromHost(); return; } if (buf_.size()< CMD1_SETINFO_SIZE) // TODO: remove magic number return; // not all data avaliable qint16 clientId=getClientId(buf_); QString caption=getClientCaption(buf_); getServer()->setClientCaption(clientId,caption); buf_ = buf_.right(buf_.size() - CMD1_SETINFO_SIZE); if (buf_.size() > 0) onDataReceived(); // If something in buffer - parse again }
bool NSocketX::sysRecv() { int read_retrycount = 3; // +1 (first time) read_again: if (from_ssaddr) { // this must be a udp socket fromlen=sizeof(from_ssaddr); sys_result = recvfrom(fd,recvbuffer,NSBUFLEN,0,(struct sockaddr *) from_ssaddr,&fromlen); } else { sys_result = recv(fd,recvbuffer,NSBUFLEN,0); } if (sys_result == SOCKET_ERROR) { error=GET_NET_ERROR(); switch (error) { case NET_ERROR_EINTR: if (read_retrycount--) goto read_again; case NET_ERROR_EAGAIN: return true; case NET_ERROR_ENOTCONN: // onInternalError("recv: Tryed to receive on an unconected socket (and should be connected)"); // break; case NET_ERROR_ENOTSOCK: // onInternalError("recv: The socket is not a socket"); // break; case NET_ERROR_EFAULT: // onInternalError("recv: The internal buffer pointer is out of range"); // break; case NET_ERROR_EINVAL: // onInternalError("recv: Invalid parameters passed"); // break; case NET_ERROR_ECONNREFUSED: // onConnectError(); sysClose(); break; default: printf("[%d] Receive error %s\n", fd, strerror(error)); listener->onSocketError(this); // XXX receive error } return false; } if (sys_result == 0) { onDisconnected(); return false; } if (!onDataReceived(recvbuffer, sys_result)) { disconnect(); return false; } else { return true; } // return true; }
DS_Client::DS_Client() { connect (&m_clientSocket, SIGNAL (readyRead()), this, SLOT (onDataReceived())); }
void testSocket::send(const vmime::string& buffer) { m_outBuffer += buffer; onDataReceived(); }
JingleSession::JingleSession(const JingleStanza &AStanza): FValid(false),FOutgoing(false),FThisParty(AStanza.to()),FOtherParty(AStanza.from()),FActionId(),FAction(IJingle::NoAction) { QDomElement jingle=AStanza.firstElement("jingle", NS_JINGLE); if (!jingle.isNull()) { QString action=jingle.attribute("action"); if (action=="session-initiate") { FSid=jingle.attribute("sid"); for (QDomElement content=jingle.firstChildElement("content"); !content.isNull(); content=content.nextSiblingElement("content")) { QDomElement description=content.firstChildElement("description"); if (!description.isNull()) { FApplicationNamespace = description.namespaceURI(); QDomElement transport=content.firstChildElement("transport"); if (!transport.isNull()) { setParent(FJingle->appByNS(FApplicationNamespace)->instance()); if (!addContent(content.attribute("name"), description, transport, content.attribute("initiator")==QString("responder"))) qWarning() << "addContent() failed!"; FValid=true; connect(this,SIGNAL(sessionAccepted(Jid,QString)),parent(), SLOT(onSessionAccepted(Jid,QString))); connect(this,SIGNAL(sessionTerminated(Jid,QString,IJingle::SessionStatus,IJingle::Reason)),parent(),SLOT(onSessionTerminated(Jid,QString,IJingle::SessionStatus,IJingle::Reason))); connect(this,SIGNAL(sessionInformed(QDomElement)),parent(),SLOT(onSessionInformed(QDomElement))); connect(this,SIGNAL(receivingData(Jid,QString)),parent(),SLOT(onDataReceived(Jid,QString))); connect(this,SIGNAL(actionAcknowledged(Jid,QString,IJingle::Action,IJingle::CommandRespond,IJingle::SessionStatus,Jid,IJingle::Reason)),parent(),SLOT(onActionAcknowledged(Jid,QString,IJingle::Action,IJingle::CommandRespond,IJingle::SessionStatus,Jid,IJingle::Reason))); } } } if (!FSessions.contains(FThisParty) || !FSessions[FThisParty].contains(FSid)) FSessions[FThisParty].insert(FSid, this); else qWarning() << "Session exists!"; } } }