Results 1 to 6 of 6

Thread: Client/server application

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Client/server application

    yes I know how send/recieve data, but I dont know how find right socket.

    server.cpp
    Qt Code:
    1. void MainWindow::startServer()
    2. {
    3. server = new QTcpServer(this);
    4. QObject::connect(server, SIGNAL(newConnection()),this, SLOT(acceptConnection()));
    5. server->listen();
    6. }
    7.  
    8. void MainWindow::acceptConnection()
    9. {
    10. QTcpSocket* socket = server->nextPendingConnection();
    11. connect(socket, SIGNAL(readyRead()), SLOT(startRead()));
    12. }
    13.  
    14. // IN THIS FUNCTION I HAVE PROBLEM!!!!
    15. void MainWindow::startRead()
    16. {
    17. QTcpSocket* socket = qobject_cast<QTcpSocket*>(this->sender());
    18. QByteArray rawdata = socket->readAll();
    19.  
    20. if(rawdata == "FINISHREADY")
    21. {
    22. // PROBLEM
    23. // the first parameter in this function must be a socket from which comes message
    24. // STARTREADY
    25. // and I dont know how find right socket
    26.  
    27. zapsat(start, "READY");
    28. }
    29. }
    30.  
    31. //write data to socket
    32. void MainWindow::writeData(QTcpSocket* socket, QByteArray data)
    33. {
    34. socket->write(data);
    35. socket->flush();
    36. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Client/server application

    So you need to store the socket pointer when you accept the connection. Where you store it is up to you.

  3. #3
    Join Date
    Mar 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Client/server application

    yes this is it, but i dont khow how to do. How to store socket pointer? I didnt find any method.

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Client/server application

    Your already storing it in local scope (QTcpSocket* socket), what you need to do is store it in a more global scope, such as in your class. Just assign, eg. clientSock = socket;

Similar Threads

  1. problem with client/server application
    By marco.stanzani in forum Newbie
    Replies: 1
    Last Post: 9th April 2011, 08:36
  2. TCP server-client application with external access
    By dominate in forum Qt Programming
    Replies: 3
    Last Post: 4th February 2011, 20:18
  3. TCP Client-Server Application
    By Tavit in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2008, 14:20
  4. Client-Server Application design suggestion
    By berzeck in forum Qt Programming
    Replies: 6
    Last Post: 17th December 2007, 19:13

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
  •  
Qt is a trademark of The Qt Company.