Results 1 to 2 of 2

Thread: QTcpServer/Socket Bidrirectional Communication

  1. #1
    Join Date
    May 2011
    Location
    Middle East
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QTcpServer/Socket Bidrirectional Communication

    Dear All,

    Am working on Server and Socket project. I want both of the server and socket talk to each other, meaning writing and reading! However, its not working! I tried the socket writing to the server, and it works great! But the server writing to the client is not working!! wat i am missing here

    Server Code:

    Qt Code:
    1. ServerOne::ServerOne(QObject* parent) : QObject(parent) {
    2. connect(&m_TcpServer8000, SIGNAL(newConnection()), this, SLOT(acceptLegacyDLIConnection()));
    3. timer = new QTimer();
    4. //here i define the signal slot of the server writing to the socket
    5. connect(timer, SIGNAL(timeout()), this, SLOT (handleWrite()));
    6. }
    7.  
    8. ServerOne::~ServerOne() {
    9. }
    10.  
    11. //accepts the incoming connection
    12. void ServerOne::acceptLegacyDLIConnection(){
    13. m_TcpSocket8000 = m_TcpServer8000.nextPendingConnection();
    14. connect(m_TcpSocket8000, SIGNAL(readyRead()), this, SLOT(handleRead()));
    15. timer->start(4000);
    16. }
    17.  
    18. //handles the incoming data from the socket
    19. void ServerOne::handleRead(){
    20. }
    21.  
    22. //handles the write to the client socket
    23. void ServerOne::handleWrite(){
    24. m_TcpSocket8000->write("In the server and writing to the client..");
    25. qDebug() << "writing..";
    26. }
    To copy to clipboard, switch view to plain text mode 

    Client Side:

    Qt Code:
    1. Client::Client(QObject* parent) :
    2. QObject(parent) {
    3. connect(client8000, SIGNAL(connected()), this, SLOT(handleWrite()));
    4. timer = new QTimer(this);
    5. connect(client8000, SIGNAL(readyRead()), this, SLOT(handleRead()));
    6. }
    7.  
    8. Client::~Client() {
    9. }
    10.  
    11. //connects the socket to the server and starts timer to send continous msgs to server
    12. void Client::connectToServer(QString address, quint16 port) {
    13. QHostAddress addr(address);
    14. client8000->connectToHost(addr, port);
    15. connect(timer, SIGNAL(timeout()), this, SLOT(handleWrite()));
    16. timer->start(2000);
    17. }
    18.  
    19. // handles the writing to server
    20. void Client::handleWrite() {
    21. }
    22.  
    23. //handles the incoming data from server
    24. void Client::handleRead() {
    25. char buffer [1024] = {0};
    26. client8000->read(buffer, client8000->bytesAvailable());
    27. cout << buffer << endl;
    28. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTcpServer/Socket Bidrirectional Communication

    Please provide a minimum compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Qt socket communication
    By ketan in forum Qt Programming
    Replies: 1
    Last Post: 3rd November 2009, 09:04
  2. Replies: 1
    Last Post: 27th March 2009, 13:20
  3. Replies: 1
    Last Post: 5th September 2008, 11:36
  4. Replies: 2
    Last Post: 23rd June 2007, 09:13
  5. Replies: 1
    Last Post: 18th June 2006, 10:12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.