Results 1 to 9 of 9

Thread: Client server based application issue (one server , multiple clients ) QT

  1. #1
    Join Date
    Nov 2015
    Location
    United States, Florida
    Posts
    6
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Post Client server based application issue (one server , multiple clients ) QT

    Hi guys,

    I have a client server Application, where multiple clients are connecting to the server . What I am doing is every time a client connects , a thread is created for that client and a sessionId is generated and stored in the Database.

    Now say for example, a client connects but somehow client is forcefully terminated (by task manager )
    Now I have a situation when trying to connect the same client - what I want is to use the same sessionID and thread and doesnot start a new thread , becuase session is already there in the database.

    Well , above mentioned funcitonality works well if there is no network (but client is running, and if network is back again, connection is established) but when client is terminated , and relogin attempt is made again, it should basically be doing the same thing repatriate the user with the old running session/Thread.

    But its not working at all.

    here is the code that is not working , basically invokeMethod is not working for the already created thread.
    Qt Code:
    1. QMetaObject::invokeMethod(entry.Connection(), "SetSocket", Qt::BlockingQueuedConnection, Q_ARG(SocketPointerStruct, socketPointerStruct));
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. qDebug()<<"User was logged in earlier, now in disconnected mode, a repatriation attempt will be made";
    2.  
    3. bool tempFlag = fSocket->disconnect();
    4. if(tempFlag)
    5. qDebug()<<"Disconnected all slots connected to fSocket";
    6. else
    7. qDebug()<<"failed to disconnected all slots connected to fSocket";
    8.  
    9. SocketPointerStruct socketPointerStruct;
    10. socketPointerStruct.fSocketPointer = fSocket;
    11. socketPointerStruct.fAutomaticLoginAttempt = automaticLoginAttempts;
    12. fSocket->moveToThread(entry.Connection()->thread());
    13. QMetaObject::invokeMethod(entry.Connection(), "SetSocket", Qt::BlockingQueuedConnection, Q_ARG(SocketPointerStruct, socketPointerStruct));
    14.  
    15. qDebug()<<"User is repatriated";
    16.  
    17. /* Set entry's connection's socket to this guys socket */
    18. fSocket = NULL;
    19. emit ended(this);
    To copy to clipboard, switch view to plain text mode 
    Problem is setSocket is never called in case client is force terminated, but if there is not network and client is still running then above code works well if network is back again.

    any pointers will be usefull.

    basically I have created a ConnectionThread class by subclassing QThread and trying the above code inside that.

    Thanks!
    Vishal
    Last edited by anda_skoa; 19th November 2015 at 09:33.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Client server based application issue (one server , multiple clients ) QT

    Any reason for the BlockingQueuedConnection vs just a QueuedConnection?
    Does the receiver thread run its event loop at this point?

    Cheers,
    _

  3. #3
    Join Date
    Nov 2015
    Location
    United States, Florida
    Posts
    6
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Client server based application issue (one server , multiple clients ) QT

    Hi,

    yes, thread is running its event loop. I tried both the options , but nothing seems to be working. (or how can i check if event loop is running? actually i tried to check if thread is running or not.... and its running... but no idea how to check if event loop is running)
    Surprisingly the same piece of code works when network is plugged out , client still running. but when client is terminated forcefully and then connected again , that piece of code doesn't invoke setSocket method as mentioned in my post.

    Thanks,
    Vishal
    Last edited by vkaushikQorvo; 19th November 2015 at 15:32.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Client server based application issue (one server , multiple clients ) QT

    Quote Originally Posted by vkaushikQorvo View Post
    yes, thread is running its event loop. I tried both the options , but nothing seems to be working. (or how can i check if event loop is running? actually i tried to check if thread is running or not.... and its running... but no idea how to check if event loop is running)
    You could run a timer in that thread that writes some log output every couple of seconds.

    Cheers,
    _

  5. #5
    Join Date
    Nov 2015
    Location
    United States, Florida
    Posts
    6
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Client server based application issue (one server , multiple clients ) QT

    Thanks!
    Yeah it seems eventLoop is running for the thread.
    ahhh, this is making me crazy now

    -vishal

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Client server based application issue (one server , multiple clients ) QT

    So you get into that method (one of the two early qDebug is logged), but the invokeMethod fails?

    Cheers,
    _

  7. #7
    Join Date
    Nov 2015
    Location
    United States, Florida
    Posts
    6
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Client server based application issue (one server , multiple clients ) QT

    What i can see is :
    bool debug3=QMetaObject::invokeMethod(entry.Connection( ), "SetSocket",Qt::BlockingQueuedConnection, Q_ARG(SocketPointerStruct, socketPointerStruct));
    qDebug()<<"User is repatriated"<<debug3;

    it never returns , qDebug() after invokeMethod is never executed.

    Regards,
    Vishal

  8. #8
    Join Date
    Nov 2015
    Location
    United States, Florida
    Posts
    6
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Client server based application issue (one server , multiple clients ) QT

    One more thing actually i forgot to mention or I realized just now, that client is terminated when it was processing some data over the socket , which means client was forcekilled and there was some data still in Qsocket stream and may be that is the reason that it never returns and invokemethod of that thread is never called.

    Can anybody please point , how can we close that socket on that thread ? or am i really overthinking on it?
    Thanks!
    vishal

  9. #9
    Join Date
    Nov 2015
    Location
    United States, Florida
    Posts
    6
    Qt products
    Qt4 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: Client server based application issue (one server , multiple clients ) QT

    Hello Qt Experts,

    please shed some light on this topic.

    Thanks!

Similar Threads

  1. Replies: 3
    Last Post: 16th August 2015, 12:32
  2. Server with multiple clients without threads
    By kernel.roy in forum Qt Programming
    Replies: 7
    Last Post: 9th September 2010, 17:37
  3. Server with multiple clients without threads
    By kernel.roy in forum Newbie
    Replies: 2
    Last Post: 9th September 2010, 05:53
  4. Replies: 0
    Last Post: 31st July 2010, 18:27
  5. Replies: 7
    Last Post: 10th May 2010, 12:26

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.