Results 1 to 7 of 7

Thread: client-server how?

  1. #1
    Join Date
    Mar 2006
    Posts
    10
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default client-server how?

    Hello Everybody

    I would like to make a client-server arcitecture with Qt 4.0, using QTcpServer and QTcpSocket. I want one server and several, say 10 clients. I also want to communicate in both directions, sending messages from server to clients (which is easy) and from clients to servers (that's the hard part).
    I tried to do it in the following way. I have a QTcpServer listening on one machine's port. I have several clients on other machines or port. First they all try to connect the server through the given hostname and port using connectToHost(). In the server whenever a new connection arrives I put the result of nextPendingConnection() to a vector containing sockets. Now this way it is easy to send anything to the clients from the server, I simply choose a socket from that vector and than send something on that socket (using QDataStream on the choosen socket, than write).
    However, I can't see how can I send anything from the clients to the server. I use the client's socket to send some data. When data arrives in the server a readyRead() signal is emitted. But how can I know which socket emitted that signal? How can I choose the right socket from my vector? I cannot even send an ID with the client, because for reading that ID the server should first know which client sent that ID. So is there any solution, or my whole arcithecture is wrong this way? If it is wrong, could you sketch some other way.

    ps. I saw that there was many thread about similar questions, but I could not find a satisfying answer anywhere, if You know about one I'm glad if you point to it.

    Thanks for Your answers
    Peter

  2. The following 2 users say thank you to nongentesimus for this useful post:

    siraansa (21st August 2006), sudeepdua (28th November 2006)

  3. #2
    Join Date
    Mar 2006
    Posts
    10
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: client-server how?

    Ok, sorry I can see that the very same question was asked and answered three threads below. So QObject::sender() does exactly what I want. Sorry for asking again

  4. #3
    Join Date
    Aug 2006
    Location
    Erlangen, Germany
    Posts
    2
    Thanks
    2
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: client-server how?

    Hallo Peter,

    Could you continue the thread, I am also working on similar project.

  5. #4
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: client-server how?

    thank you very much
    sudeepdua

  6. #5
    Join Date
    Nov 2006
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: client-server how?

    I'm facing a problem ... i have made the same application but i keep getting the string from the server 2 times when reading from the client even if i send it only once...... i have got some clue saying that i have to clear socket ..... but how >??
    sudeepdua

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: client-server how?

    Maybe the Simple Chat example in our wiki could be of some use..
    It uses a QHash to store the clients and QObject::sender() to identify them. Pretty much something what nongentesimus already suggested as a solution.
    J-P Nurmi

  8. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: client-server how?

    Quote Originally Posted by sudeepdua View Post
    I'm facing a problem ... i have made the same application but i keep getting the string from the server 2 times when reading from the client even if i send it only once...... i have got some clue saying that i have to clear socket ..... but how >??
    Sounds like a problem of the buffering technique. Check out the example mentioned in my previous post. It uses QBuffer to handle all transmission data.
    J-P Nurmi

Similar Threads

  1. Fix: QT app won't run under Oracle Standard Client install
    By GreyGeek in forum General Discussion
    Replies: 0
    Last Post: 12th May 2006, 18:20
  2. How do I keep the client connection open ?
    By probine in forum Newbie
    Replies: 2
    Last Post: 25th March 2006, 19:06
  3. The server cannot write to the client. Why?
    By probine in forum Newbie
    Replies: 12
    Last Post: 24th March 2006, 17:14
  4. Asynchronous server msg vs synchronous functions
    By nouknouk in forum Qt Programming
    Replies: 9
    Last Post: 2nd February 2006, 17:10
  5. synching client readings to server output
    By OnionRingOfDoom in forum Qt Programming
    Replies: 14
    Last Post: 28th January 2006, 18:15

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.