yes I know how send/recieve data, but I dont know how find right socket.
server.cpp
void MainWindow::startServer()
{
QObject::connect(server,
SIGNAL(newConnection
()),
this,
SLOT(acceptConnection
()));
server->listen();
}
void MainWindow::acceptConnection()
{
QTcpSocket* socket
= server
->nextPendingConnection
();
connect(socket, SIGNAL(readyRead()), SLOT(startRead()));
}
// IN THIS FUNCTION I HAVE PROBLEM!!!!
void MainWindow::startRead()
{
QTcpSocket* socket
= qobject_cast<QTcpSocket
*>
(this
->sender
());
if(rawdata == "FINISHREADY")
{
// PROBLEM
// the first parameter in this function must be a socket from which comes message
// STARTREADY
// and I dont know how find right socket
zapsat(start, "READY");
}
}
//write data to socket
{
socket->write(data);
socket->flush();
}
void MainWindow::startServer()
{
server = new QTcpServer(this);
QObject::connect(server, SIGNAL(newConnection()),this, SLOT(acceptConnection()));
server->listen();
}
void MainWindow::acceptConnection()
{
QTcpSocket* socket = server->nextPendingConnection();
connect(socket, SIGNAL(readyRead()), SLOT(startRead()));
}
// IN THIS FUNCTION I HAVE PROBLEM!!!!
void MainWindow::startRead()
{
QTcpSocket* socket = qobject_cast<QTcpSocket*>(this->sender());
QByteArray rawdata = socket->readAll();
if(rawdata == "FINISHREADY")
{
// PROBLEM
// the first parameter in this function must be a socket from which comes message
// STARTREADY
// and I dont know how find right socket
zapsat(start, "READY");
}
}
//write data to socket
void MainWindow::writeData(QTcpSocket* socket, QByteArray data)
{
socket->write(data);
socket->flush();
}
To copy to clipboard, switch view to plain text mode
Bookmarks