Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. TCP server, show only the selected clients messages
Forum Updated to NodeBB v4.3 + New Features

TCP server, show only the selected clients messages

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thehilmisu
    wrote on last edited by
    #1

    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));
    if(server->isListening())
    {
    ui->statusBar->showMessage("Server Started..");
    }
    else
    {
    ui->statusBar->showMessage("Server Not Started..");
    }

    connect(client,SIGNAL(disconnected()),this,SLOT(client_disconnected()));
    
    connect(ui->listWidget,SIGNAL(clicked(QModelIndex)),this,SLOT(selected_client()));
    

    @

    here is acceptConnection() part

    @
    client = server->nextPendingConnection();

    ui->listWidget->insertItem(client_count,client->peerAddress().toString());
    client_count++;
    

    @

    and this is the listWidget item's selected item event

    @
    ui->txtRead->clear();
    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;
    ui->txtRead->insertPlainText(buffer);
    @

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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca.cossaro
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thehilmisu
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved