Important: Please read the Qt Code of Conduct -

TCP server, show only the selected clients messages

  • I am developing a simple tcp server with qt. There is no problem with that. But the problem is, i have listed every connected client in a listbox and i want to see the incoming data only from the selected client from the listbox but i can only see the last connected client's messages. here is the code, this is the constructor part
    server = new QTcpServer();
    client = new QTcpSocket();
    connect(server, SIGNAL(newConnection()),this, SLOT(acceptConnection()));
    server->listen(QHostAddress::Any, ui->txtPort->text().toInt(bool(),10));
    ui->statusBar->showMessage("Server Started..");
    ui->statusBar->showMessage("Server Not Started..");



    here is acceptConnection() part

    client = server->nextPendingConnection();



    and this is the listWidget item's selected item event

    selected_client_index = ui->listWidget->currentIndex().row();
    connect(client, SIGNAL(readyRead()),this, SLOT(startRead()));

    and lastly the startRead() part

    char buffer[1024] = {0};
    client->read(buffer, client->bytesAvailable());
    qDebug() << buffer;

    How can i select the specific client and show its messages ?
    Thanks in advance.

  • You should have a list of clients instances not only one.

  • yes i have created @QList<QTcpSocket*> client_list;@ and append every client in it.

Log in to reply