Results 1 to 9 of 9

Thread: Commands exchange between Client and Server

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    50
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: Commands exchange between Client and Server

    I don`t understant: is there a problem to create a personal thread for every client connecting and destroy the thread when he disconnects? I have to write the same project and i`m going to do it with opening new thread for every new connection and then open separate SQL connection to the server for reading/writing data. Why you think to change that behavior with the threads?

  2. #2
    Join Date
    Sep 2009
    Posts
    22
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Commands exchange between Client and Server

    I don't think that my problem is related to server side thread. Well... maybe it is possible, but in my opinion is improbable!
    I'm going to change this behaviour because of the delay between the connection and the signal connected(). If this is too long, the command id can change between the first and the second command to send... Result: only the second command is sent!
    If it is difficult to understand the problem, try to imagine to call 2 times the function SomeCommand() with different cmdId:

    SomeCommand(cmdId =3);
    SomeCommand(cmdId = 4);

    The connection starts with cmdId = 3, but signal connected() arrives late... that's why the SomeCommand(cmdId=4) is executed before the function sendCommand is executed. So only the second command is sent. Is that clear now?

  3. #3
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: Commands exchange between Client and Server

    Just a couple of things:
    1. If you have to serve more than 1 client at a time or you have to run multiple commands simultaneously - use your own QThread reimplementation or have a look at QFuture.

    2. Don't reopen the socket multiple times. Some firewalls consider that an attack (see SNORT for details).

    3. A nice TCP/IP documentation is your friend. Just try to realize how it should work, compare to Qt implementation and you'll get that very fast.

    Good luck.

  4. #4
    Join Date
    Sep 2009
    Posts
    22
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: Commands exchange between Client and Server

    I implemented the solution planned some posts ago... It seems to work well!
    Now all commands arrive to the server application!
    However initially I've seen that 2 commands very near in time were not executed... I was really going crazy!!! Luckily, I noticed that there was also a problem in the server application: if two commands arrive at the same time, the function connected to the signal readyRead() is called only one time, and so executes only the first command.
    To solve this problem, I've made a control over the socket buffer (based on the method bytesAvailable()): if at the end of the first command there are other bytes in the buffer, I call the function to read commands another time! In this way I'm sure to execute all the commands received in the buffer!
    I don't know if this is the best solution... Anyway, at the moment It works!!!
    If at debug time I discover some problems, surely I let you know!
    Thanks for all contributions! If any of you needs some more deep explanations for this problem, ask!

    See you all!
    Alex

Similar Threads

  1. TCP server client threads
    By jmsbc in forum Qt Programming
    Replies: 0
    Last Post: 17th November 2009, 19:10
  2. [PyQt4] SSL server and client example
    By JoelG90 in forum Newbie
    Replies: 1
    Last Post: 24th May 2009, 09:09
  3. Replies: 0
    Last Post: 22nd February 2009, 13:15
  4. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 12:05
  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
  •  
Qt is a trademark of The Qt Company.