Results 1 to 4 of 4

Thread: Command-Based Client (TCP)

  1. #1
    Join Date
    Jul 2009
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Command-Based Client (TCP)

    Hello Everyone,

    I am qurrently working on a TCP-Client, which needs to become command Based.

    I have already "prepared" a protocol to this purpose, by sending a command-ID with each data package, which the server can base its response on.

    My current problem lies on the fact that i will have many objects sending commands to the server and in some cases they will expect a response.

    Now I am unsure how to organize this best specially without blocking the socket.

    Should I use Threads for each sender that expects a response?

    or

    Should I try to implement a ticketing of sorts? For which each command sent will get a number and this will need to be attached to the corresponding response... (sounds complicated! )

    or

    ???

    I'm looking for some insight or a nudge in the "right" direction.

    (Hope someone understands what i have tried to ask.... )

    Thanks

    Eric
    Last edited by ericV; 31st August 2009 at 16:12.

  2. #2
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Command-Based Client (TCP)

    I faced a similar situation two years ago when we started designing an application that communicates with an Asterisk Manager (plain text messages on port 5038).

    I created a thread that connects and manages the messages. It uses an event loop and non-blocking API. A private class parses the messages and emits a signal for every kind of event. In every part of the program that needs a response, you can just connect the signal to a slot.

    It's working pretty fine. You could the same.

  3. #3
    Join Date
    Jul 2009
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Command-Based Client (TCP)

    Thank you for that.

    I am still strugling a bit with this problem, here is why:

    - my application will have many different grafical objects, which may request different types of data from the server.

    So i need to identify the request sender somehow in order to send the response to the "right" object.

    I am running around in circles because of this....

    Had thought about using QLocalServer with QLocalSockets from each object... but it seems to me that this wouldnt be the best way....

    An other idea that I have, is to create a RequestThread... that can be called from each object... which then emits a signal when the response has arrived (probably a cleaner aproach)

    I will try to experiment on this...

  4. #4
    Join Date
    Feb 2008
    Posts
    98
    Thanks
    2
    Thanked 24 Times in 24 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Command-Based Client (TCP)

    Use signals and slots. An object that needs some type of data should connect a signal from the server to itself. When the object wants to request some particular data, it would call one of the server backend slots and some time later one of the object's slots would be invoked. This way the server doesn't need to care about your objects.

Similar Threads

  1. WebIssues Client 0.9.5
    By mimec in forum Qt-based Software
    Replies: 0
    Last Post: 17th August 2009, 12:01
  2. Connected client tree
    By cooler123 in forum Qt Programming
    Replies: 7
    Last Post: 13th July 2009, 20:49
  3. Replies: 0
    Last Post: 22nd February 2009, 13:15
  4. Client side password management
    By frikkasoft in forum Qt Programming
    Replies: 2
    Last Post: 12th December 2008, 10:23
  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.