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. Qt TcpMultiThread Server
Forum Updated to NodeBB v4.3 + New Features

Qt TcpMultiThread Server

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 235 Views
  • 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.
  • K Offline
    K Offline
    Krizbiii
    wrote on last edited by aha_1980
    #1

    Hey
    I have some problem with my TCP Server.

    void MyThread::readyRead(){
        //auto socket = qobject_cast<QTcpSocket *>(sender());
    
        QByteArray Data = socket->readAll();
        qDebug() << socketDescriptor <<"Data in : "<< Data;
        socket ->write(Data); //Its work
        //Send message for all Client (socket)
        for( int i=0; i < ClientList.count(); ++i ) {
            QTcpSocket* writeforsocket = ClientList.at(i);
            //crash here
            writeforsocket->write("Text");  //DIDINT WORK
    
            writeforsocket->flush();
            writeforsocket->waitForBytesWritten(3000);
            //writeforsocket->write(CurrentImg); // Write The Encoded Image
            writeforsocket->flush();
        }
    }
    
    J.HilkJ 1 Reply Last reply
    0
    • K Krizbiii

      Hey
      I have some problem with my TCP Server.

      void MyThread::readyRead(){
          //auto socket = qobject_cast<QTcpSocket *>(sender());
      
          QByteArray Data = socket->readAll();
          qDebug() << socketDescriptor <<"Data in : "<< Data;
          socket ->write(Data); //Its work
          //Send message for all Client (socket)
          for( int i=0; i < ClientList.count(); ++i ) {
              QTcpSocket* writeforsocket = ClientList.at(i);
              //crash here
              writeforsocket->write("Text");  //DIDINT WORK
      
              writeforsocket->flush();
              writeforsocket->waitForBytesWritten(3000);
              //writeforsocket->write(CurrentImg); // Write The Encoded Image
              writeforsocket->flush();
          }
      }
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @Krizbiii and welocme

      Most likely your ClientList does not contain a valid pointer to a QTcpSocket instance.

      You should check that


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      5
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        I see a number of potential things going wrong here. Let's start with the most obvious one, what is ClientList? who owns it?

        As a separate but important point. Why are you using multithreading to manage TCP socket? if it's to allow multiple connections it's a misconception born from the fortune client/server example being not very clear.

        You can check out this example for an hopefully clearer explanation

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        5

        • Login

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