//! [clientConnected] void TennisServer::clientConnected() { qDebug() << Q_FUNC_INFO << "connect"; QBluetoothSocket *socket = l2capServer->nextPendingConnection(); if (!socket) return; if(clientSocket){ qDebug() << Q_FUNC_INFO << "Closing socket!"; delete socket; return; } connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(socketError(QBluetoothSocket::SocketError))); stream = new QDataStream(socket); clientSocket = socket; qDebug() << Q_FUNC_INFO << "started"; emit clientConnected(clientSocket->peerName()); lagTimer.start(); }
void QServer::addToList(QLocalSocket* socket) { //Store sockets & connect them for read & discard them on disconnect connection_list.push_back(socket); connect(socket, SIGNAL(readyRead()), this , SLOT(readSocket())); connect(socket, SIGNAL(disconnected()), this , SLOT(discardSocket())); }
void HttpServer :: incomingConnection(qintptr socketDescriptor) { auto socket = new QTcpSocket (this); connect (socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect (socket, SIGNAL(disconnected()), this, SLOT(disconnectSocket())); socket->setSocketDescriptor(socketDescriptor); }
void PingPong::clientConnected() { //! [Initiating server socket] if (!m_serverInfo->hasPendingConnections()) { setMessage("FAIL: expected pending server connection"); return; } socket = m_serverInfo->nextPendingConnection(); if (!socket) return; socket->setParent(this); connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(socketError(QBluetoothSocket::SocketError))); //! [Initiating server socket] setMessage(QStringLiteral("Client connected.")); QByteArray size; size.setNum(m_boardWidth); size.append(' '); QByteArray size1; size1.setNum(m_boardHeight); size.append(size1); size.append(" \n"); socket->write(size.constData()); }
void SocketThread::run() { { queryTime.restart(); if(isLogEnabled)logThread->writeLog("SocketThread Started"); sslSocket=new QSslSocket; connect(this,SIGNAL(sendToApiSignal(QByteArray, QByteArray)),this,SLOT(sendToApiSlot(QByteArray, QByteArray))); connect(this,SIGNAL(reconnectApiSignal()),this,SLOT(reconnectApiSlot())); connect(sslSocket,SIGNAL(readyRead()),SLOT(readSocket())); secondTimer=new QTimer; connect(secondTimer,SIGNAL(timeout()),this,SLOT(secondSlot())); if(useSSL)sslSocket->connectToHostEncrypted(hostName, 443); else sslSocket->connectToHost(hostName, 80); sslSocket->waitForConnected(); if(isLogEnabled) { logThread->writeLog("SSL Socket state:"+sslSocket->errorString().toAscii()+". Supported: "+QByteArray::number(sslSocket->supportsSsl())); } secondTimer->start(100); sendPendingData(); } exec(); }
//! [startClient] void RfCommClient::startClient(const QBluetoothServiceInfo &remoteService) { qDebug() << __PRETTY_FUNCTION__ << ">>"; serviceInfo = remoteService; // make sure preconditions are met if (!powerOn() || socket) { qDebug() << __PRETTY_FUNCTION__ << "<< power not on or socket already exists!"; return; } // Connect to service if (state == listening) state = pendingConnections; socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket); qDebug() << "Create socket"; socket->connectToService(remoteService); qDebug() << "ConnecttoService done"; connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(error(QBluetoothSocket::SocketError))); qDebug() << __PRETTY_FUNCTION__ << "<<"; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow),media(0) { isConnected=false; controllerConnected=false; ui->setupUi(this); this->setWindowTitle("Au2"); instance = new VlcInstance(VlcCommon::args(), this); player = new VlcMediaPlayer(instance); player->setVideoWidget(ui->video); readDataFromFile(); data[1] = 0;//hastighed data[2] = 0;//afstand data[3] = 0;//acceleration data[4] = 1;//AKS = on ui->AKS->setText("AKS-On"); updateData(); connect(ui->OpretForbindelse, SIGNAL(clicked()), this, SLOT(Au2connect())); connect(ui->KonfigurerIP, SIGNAL(clicked()), this, SLOT(konfigurerIP())); connect(ui->AKS, SIGNAL(clicked()), this, SLOT(AKSstatus())); connect(ui->IndstilMaksHastighed, SIGNAL(clicked()), this, SLOT(maksHastighed())); connect(ui->KalibrerStyretoj, SIGNAL(clicked()), this, SLOT(kalibrerStyretoj())); connect(ui->LukNed, SIGNAL(clicked()), this, SLOT(shutDown())); connect(this, SIGNAL(sig_getData()), this, SLOT(readSocket())); }
void LocalSocketConnection::start() { if (m_socket) { m_holdRequests = false; while (m_socket->bytesAvailable() != 0) readSocket(); } }
Connection::Connection(QObject *parent) : QObject(parent) { conection = new QLocalSocket(this); connect(conection,SIGNAL(readyRead()),this,SLOT(readSocket())); connect(conection,SIGNAL(disconnected()),this,SLOT(discardSocket())); conection->connectToServer(Packets::server_name_tag); }
//! [clientConnected] void ChatServer::clientConnected() { QBluetoothSocket *socket = rfcommServer->nextPendingConnection(); if (!socket) return; connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(disconnected()), this, SLOT(clientDisconnected())); clientSockets.append(socket); emit clientConnected(socket->peerName()); }
Boolean Groupsock::handleRead(unsigned char* buffer, unsigned bufferMaxSize, unsigned& bytesRead, struct sockaddr_in& fromAddress) { // Read data from the socket, and relay it across any attached tunnels //##### later make this code more general - independent of tunnels bytesRead = 0; int maxBytesToRead = bufferMaxSize - TunnelEncapsulationTrailerMaxSize; int numBytes = readSocket(env(), socketNum(), buffer, maxBytesToRead, fromAddress); if (numBytes < 0) { if (DebugLevel >= 0) { // this is a fatal error env().setResultMsg("Groupsock read failed: ", env().getResultMsg()); } return False; } // If we're a SSM group, make sure the source address matches: if (isSSM() && fromAddress.sin_addr.s_addr != sourceFilterAddress().s_addr) { return True; } // We'll handle this data. // Also write it (with the encapsulation trailer) to each member, // unless the packet was originally sent by us to begin with. bytesRead = numBytes; int numMembers = 0; if (!wasLoopedBackFromUs(env(), fromAddress)) { statsIncoming.countPacket(numBytes); statsGroupIncoming.countPacket(numBytes); numMembers = outputToAllMembersExcept(NULL, ttl(), buffer, bytesRead, fromAddress.sin_addr.s_addr); if (numMembers > 0) { statsRelayedIncoming.countPacket(numBytes); statsGroupRelayedIncoming.countPacket(numBytes); } } if (DebugLevel >= 3) { env() << *this << ": read " << bytesRead << " bytes from "; env() << our_inet_ntoa(fromAddress.sin_addr); if (numMembers > 0) { env() << "; relayed to " << numMembers << " members"; } env() << "\n"; } return True; }
void receiver(int socket, char *filename) { fd_set read, write; char readed[520]; int f; if(filename==NULL) f=STDOUT_FILENO; else f=open(filename,O_WRONLY|O_CREAT|O_TRUNC); while(1){ FD_ZERO(&read); FD_ZERO(&write); FD_SET(socket,&write); FD_SET(socket,&read); FD_SET(f,&write); if(select(socket+1,&read,&write, NULL,NULL)==-1) { fprintf(stderr,"Error selectreceiver\n"); return; } if(FD_ISSET(socket,&write) && FD_ISSET(socket,&read)) { printf("receiver readwritesocket\n"); int rd=readSocket(socket,readed,520); if(rd>=0) { pkt_t *pkt=pkt_new(); pkt_status_code errdec=pkt_decode((const char *)readed,(size_t)rd,pkt); printf("lu : %s\n",pkt_get_payload(pkt)); if(errdec==PKT_OK) { if(pkt_get_type(pkt)==PTYPE_DATA) { printf("On doit créer ACK/NACK\n"); } } else { fprintf(stderr,"Error receiver decode\n"); return; } pkt_del(pkt); printf("after del\n"); } } else if(FD_ISSET(f,&write)) { printf("Write file\n"); break; } } }
void PingPong::addService(const QBluetoothServiceInfo &service) { setMessage("Service found. Setting parameters..."); //! [Connecting the socket] socket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol); socket->connectToService(service); connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(connected()), this, SLOT(serverConnected())); connect(socket, SIGNAL(disconnected()), this, SLOT(serverDisconnected())); //! [Connecting the socket] m_serviceFound = true; }
void LCDServer::newConnection(QTcpSocket *socket) { connect(socket, SIGNAL(readyRead()), this, SLOT( readSocket())); connect(socket, SIGNAL(disconnected()), this, SLOT( endConnection())); if (debug_level > 0) LOG(VB_NETWORK, LOG_INFO, "LCDServer: new connection"); if (m_lcd) m_lcd->switchToTime(); }
void iControlPadClient::connectToService(const QBluetoothServiceInfo &remoteService) { if (m_socket) return; // Connect to service m_socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket); qDebug() << "Create socket"; m_socket->connectToService(remoteService); qDebug() << "Connecte Service done"; connect(m_socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(m_socket, SIGNAL(connected()), this, SLOT(connected())); connect(m_socket, SIGNAL(disconnected()), this, SLOT(disconnected())); }
//! [startClient] void ChatClient::startClient(const QBluetoothServiceInfo &remoteService) { if (socket) return; // Connect to service socket = new QBluetoothSocket(QBluetoothSocket::RfcommSocket); qDebug() << "Create socket"; socket->connectToService(remoteService); qDebug() << "ConnecttoService done"; connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); }
RunnerView::RunnerView(QString appUid, QString server, QWidget* parent) : QQuickWidget(parent), m_appUid(appUid), m_socket(new QLocalSocket(this)), m_shared(new QSharedMemory(appUid, this)) { qDebug() << "RunnerView::RunnerView"; connect(engine(), SIGNAL(quit()), this, SLOT(quitApplication())); connect(m_socket, SIGNAL(connected()), this, SLOT(socketConnected())); connect(m_socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); connect(m_socket, SIGNAL(error(QLocalSocket::LocalSocketError)), this, SLOT(socketError(QLocalSocket::LocalSocketError))); connect(m_socket, SIGNAL(bytesWritten(qint64)), this, SLOT(socketBytesWritten(qint64))); connect(m_socket, SIGNAL(readyRead()), this, SLOT(readSocket())); m_socket->connectToServer(server); qDebug() << "RunnerView::RunnerView - END"; }
void ServerThread::run() { _tcpSocket = new QTcpSocket(); //qDebug () << "Setting socket descriptor " << _socketDescriptor; if (!_tcpSocket->setSocketDescriptor(_socketDescriptor)) { qDebug() << "Cant set socket descriptor " << _socketDescriptor << " " << _tcpSocket->errorString(); return; } connect(_tcpSocket, SIGNAL(readyRead()), this, SLOT(readSocket()), Qt::DirectConnection); connect(_tcpSocket, SIGNAL(disconnected()), this, SLOT(handleSocketDisconnect()), Qt::DirectConnection); exec(); }
void RTSPServer::RTSPClientSession::incomingRequestHandler1() { noteLiveness(); struct sockaddr_in dummy; // 'from' address, meaningless in this case Boolean endOfMsg = False; unsigned char* ptr = &fRequestBuffer[fRequestBytesAlreadySeen]; int bytesRead = readSocket(envir(), fClientSocket, ptr, fRequestBufferBytesLeft, dummy); if (bytesRead <= 0 || (unsigned)bytesRead >= fRequestBufferBytesLeft) { // Either the client socket has died, or the request was too big for us. // Terminate this connection: #ifdef DEBUG fprintf(stderr, "RTSPClientSession[%p]::incomingRequestHandler1() read %d bytes (of %d); terminating connection!\n", this, bytesRead, fRequestBufferBytesLeft); #endif delete this; return; } #ifdef DEBUG ptr[bytesRead] = '\0'; fprintf(stderr, "RTSPClientSession[%p]::incomingRequestHandler1() read %d bytes:%s\n", this, bytesRead, ptr); #endif // Look for the end of the message: <CR><LF><CR><LF> unsigned char *tmpPtr = ptr; if (fRequestBytesAlreadySeen > 0) --tmpPtr; // in case the last read ended with a <CR> while (tmpPtr < &ptr[bytesRead-1]) { if (*tmpPtr == '\r' && *(tmpPtr+1) == '\n') { if (tmpPtr - fLastCRLF == 2) { // This is it: endOfMsg = 1; break; } fLastCRLF = tmpPtr; } ++tmpPtr; } fRequestBufferBytesLeft -= bytesRead; fRequestBytesAlreadySeen += bytesRead; if (!endOfMsg) return; // subsequent reads will be needed to complete the request fRequestBuffer[fRequestBytesAlreadySeen] = '\0'; handleRequest(); }
void *testReaderUnix(void *) { UDDSocket readSocket("testDestination"); readSocket.nonblocking(); int rc = 0; while (rc<gNumToSend) { char buf[MAX_UDP_LENGTH]; int count = readSocket.read(buf); if (count>0) { COUT("read: " << buf); rc++; } else { sleep(2); } } return NULL; }
void *testReaderIP(void *) { UDPSocket readSocket(5934, "localhost", 5061); readSocket.nonblocking(); int rc = 0; while (rc<gNumToSend) { char buf[MAX_UDP_LENGTH]; int count = readSocket.read(buf); if (count>0) { COUT("read: " << buf); rc++; } else { sleep(2); } } return NULL; }
int ServerSocket::listenOnSocket() { int listenErr = listen(this->sockfd, BACKLOG); if (listenErr != 0) { printf("\nSocket Listen FAILED! %d\n", errno); return cleanup(); } printf("\nListening on %d...", PORT); acceptConnection(); printf("\nConnection Accepted!"); char *buf = new char[128]; char *start = buf; int len = readSocket(buf); printf("\nReceived %d bytes", len); printf("\nReceived %s", start); writeToSocket("RESPONSE"); return 0; }
void LocalSocketConnection::setSocket(QLocalSocket *socket) { if (m_socket != NULL) { m_socket->abort(); m_socket->disconnect(this); disconnect(m_socket); m_socket->deleteLater(); } if (socket != NULL) { connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); connect(socket, SIGNAL(destroyed()), this, SLOT(socketDestroyed())); } m_dataStream->setDevice(socket); m_dataStream->setVersion(QDataStream::Qt_4_8); m_socket = socket; }
void QxThread::doProcess(QTcpSocket & socket) { if (! socket.setSocketDescriptor(m_iSocketDescriptor)) { Q_EMIT error("[QxOrm] invalid socket descriptor : cannot start transaction", QxTransaction_ptr()); return; } qx_bool bReadOk = readSocket(socket); if (! bReadOk) { Q_EMIT error(QString("[QxOrm] unable to read request from socket : '") + bReadOk.getDesc() + QString("'"), QxTransaction_ptr()); return; } if (! m_bIsRunning) { return; } Q_EMIT transactionStarted(m_pTransaction); try { m_pTransaction->executeServer(); } catch (const qx::exception & x) { qx_bool xb = x.toQxBool(); m_pTransaction->setMessageReturn(xb); } catch (const std::exception & e) { m_pTransaction->setMessageReturn(qx_bool(QX_ERROR_UNKNOWN, e.what())); } catch (...) { m_pTransaction->setMessageReturn(qx_bool(QX_ERROR_UNKNOWN, "unknown error")); } if (! m_bIsRunning) { return; } qx_bool bWriteOk = writeSocket(socket); if (! bWriteOk) { Q_EMIT error(QString("[QxOrm] unable to write reply to socket : '") + bWriteOk.getDesc() + QString("'"), m_pTransaction); } Q_EMIT transactionFinished(m_pTransaction); }
int readSocketExact(UsageEnvironment& env, int socket, unsigned char* buffer, unsigned bufferSize, struct sockaddr_in& fromAddress, struct timeval* timeout) { /* read EXACTLY bufferSize bytes from the socket into the buffer. fromaddress is address of last read. return the number of bytes actually read when an error occurs */ int bsize = bufferSize; int bytesRead = 0; int totBytesRead =0; do { bytesRead = readSocket (env, socket, buffer + totBytesRead, bsize, fromAddress, timeout); if (bytesRead <= 0) break; totBytesRead += bytesRead; bsize -= bytesRead; } while (bsize != 0); return totBytesRead; }
void LocalSocketConnection::readSocket() { if(!m_socket->isValid()) return; if (m_holdRequests) return; if (m_socket->bytesAvailable() == 0) return; PacketType packet; (*m_dataStream) >> packet; emit packetReceived(packet, EndpointIdType()); // Check again in 50 ms if no more data is available, or immediately if there // is. This helps ensure that burst traffic is handled robustly. QTimer::singleShot(m_socket->bytesAvailable() > 0 ? 0 : 50, this, SLOT(readSocket())); }
//! [startClient] void TennisClient::startClient(const QBluetoothServiceInfo &remoteService) { if (socket) return; serviceInfo = remoteService; // Connect to service socket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol); qDebug() << "Create socket"; socket->connectToService(remoteService); qDebug() << "ConnecttoService done"; connect(socket, SIGNAL(readyRead()), this, SLOT(readSocket())); connect(socket, SIGNAL(connected()), this, SLOT(connected())); connect(socket, SIGNAL(disconnected()), this, SIGNAL(disconnected())); connect(socket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(error(QBluetoothSocket::SocketError))); lagTimer.start(); }
bool RTMP::readPacketPayload(RTMPPacket& packet) { RTMPHeader& hr = packet.header; const size_t bytesRead = packet.bytesRead; const int nToRead = hr.dataSize - bytesRead; const int nChunk = std::min<int>(nToRead, _inChunkSize); assert(nChunk >= 0); // This is fine. We'll keep trying to read this payload until there // is enough data. if (readSocket(payloadData(packet) + bytesRead, nChunk) != nChunk) { return false; } packet.bytesRead += nChunk; return true; }
bool Connection::recvPacket() { while (true) { if (m_reader.havePacket()) { break; } if (!readSocket()) { return false; } if (m_reader.havePacket()) { break; } } return true; }
void QxTransaction::executeClient(IxService * pService, const QString & sMethod) { if ((pService == NULL) || sMethod.isEmpty()) { qAssert(false); return; } if (pService->getServiceName().isEmpty()) { pService->setMessageReturn(qx_bool(QX_ERROR_SERVICE_NOT_SPECIFIED, "[QxOrm] empty service name")); return; } pService->registerClass(); QTcpSocket socket; QString serverName = QxConnect::getSingleton()->getIp(); long serverPort = QxConnect::getSingleton()->getPort(); socket.connectToHost(serverName, serverPort); if (! socket.waitForConnected(QxConnect::getSingleton()->getMaxWait())) { pService->setMessageReturn(qx_bool(QX_ERROR_SERVER_NOT_FOUND, "[QxOrm] unable to connect to server")); return; } if (m_sTransactionId.isEmpty()) { setTransactionId(QUuid::createUuid().toString()); } setIpSource(socket.localAddress().toString()); setPortSource(socket.localPort()); setIpTarget(serverName); setPortTarget(serverPort); setServiceName(pService->getServiceName()); setServiceMethod(sMethod); setTransactionBegin(QDateTime::currentDateTime()); setInputParameter(pService->getInputParameter_BaseClass()); qx_bool bWriteOk = writeSocket(socket); if (! bWriteOk) { pService->setMessageReturn(qx_bool(QX_ERROR_SERVICE_WRITE_ERROR, QString("[QxOrm] unable to write request to socket : '") + bWriteOk.getDesc() + QString("'"))); return; } qx_bool bReadOk = readSocket(socket); if (! bReadOk) { pService->setMessageReturn(qx_bool(QX_ERROR_SERVICE_READ_ERROR, QString("[QxOrm] unable to read reply from socket : '") + bReadOk.getDesc() + QString("'"))); return; } pService->setOutputParameter(getOutputParameter()); pService->setMessageReturn(getMessageReturn()); setTransactionEnd(QDateTime::currentDateTime()); socket.disconnectFromHost(); if (socket.state() != QAbstractSocket::UnconnectedState) { socket.waitForDisconnected(QxConnect::getSingleton()->getMaxWait()); } }