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. Sending data with QTcpSocket issue
Qt 6.11 is out! See what's new in the release blog

Sending data with QTcpSocket issue

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.5k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I'm working on a client/server project with Qt to have a client and a server. Basically, I'm trying to get core functionality tested and working before building more on top of it (for a basic IM client for a project in school). I'm designing my message passing syntax so that I can automate the IM client a little bit.

    This is my readyRead() slot for the readyRead signal, server side. I'll mark the trouble spot with an all caps comment.

    @ if (stuff == "REG\n") //client would like to register. next message should be username
    {//need to add check to see if user exists
    socket->write("ACK"); //this is a hard ack that tells the client that it may write to the socket and be heard by the server.
    stuff.clear(); //verify that buffer is cleared.
    socket->waitForReadyRead();
    stuff=socket->readAll();//should have username followed by \n
    stuffText = stuff; //move it to a string so that I can manually remove the \n and then add it to the users list.
    stuffText.remove('\n'); //hopefully removes the \n
    //now to add to the user list, completing the register process.
    temp.setName(stuffText);
    temp.setDescriptor(this->socketDescriptor);//temp user configured. time to add
    lock.lock();
    users.append(temp);
    lock.unlock();
    //clean up
    stuff.clear();
    stuffText.clear();
    temp.clear();
    stuff="ACK";
    if(!socket->write(stuff))//THIS IS WHERE I'M HAVING TROUBLE
    {
    qDebug() << "Didn't work.";
    }
    //client has been added to the list. waiting for other data.
    }@

    At all-caps comment, everything up to that point has worked just fine. The client sends a REG request, the server responds (I know that the underlying protocol uses ACKs, I'm just sending back a known bit of text that I can test for). After the server response, my test client then sends the username it wishes to register, and the server gets it and parses it correctly, locks the shared memory location, writes, unlocks. Everything works well. Then I get to sending the ACK again, and though the server thinks it's sent it (at least, I think the criteria for the if should be right), but the client does not receive anything.

    Am I doing something wrong?

    Thank for any help,
    Sean

    1 Reply Last reply
    0
    • M Offline
      M Offline
      melghawi
      wrote on last edited by
      #2

      Hi seanr8. What does your client-side look like? If your server is having a hard time sending data across a TCP socket it generally means that the connection was broken for some reason.

      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