//! [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()); }
//! [readSocket] void ChatServer::readSocket() { QBluetoothSocket *socket = qobject_cast<QBluetoothSocket *>(sender()); if (!socket) return; while (socket->canReadLine()) { QByteArray line = socket->readLine().trimmed(); emit messageReceived(socket->peerName(), QString::fromUtf8(line.constData(), line.length())); } }
//! [clientDisconnected] void ChatServer::clientDisconnected() { QBluetoothSocket *socket = qobject_cast<QBluetoothSocket *>(sender()); if (!socket) return; emit clientDisconnected(socket->peerName()); clientSockets.removeOne(socket); socket->deleteLater(); }
//! [clientDisconnected] void TennisServer::clientDisconnected() { qDebug() << Q_FUNC_INFO << "client closing!"; lagTimer.stop(); lagReplyTimeout = 0; QBluetoothSocket *socket = qobject_cast<QBluetoothSocket *>(sender()); if (!socket) return; emit clientDisconnected(socket->peerName()); clientSocket->deleteLater(); clientSocket = 0; delete stream; stream = 0; // socket->deleteLater(); }