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.
QMetaObject::invokeMethod(entry.
Connection(),
"SetSocket", Qt
::BlockingQueuedConnection, Q_ARG
(SocketPointerStruct, socketPointerStruct
));
QMetaObject::invokeMethod(entry.Connection(), "SetSocket", Qt::BlockingQueuedConnection, Q_ARG(SocketPointerStruct, socketPointerStruct));
To copy to clipboard, switch view to plain text mode
qDebug()<<"User was logged in earlier, now in disconnected mode, a repatriation attempt will be made";
bool tempFlag = fSocket->disconnect();
if(tempFlag)
qDebug()<<"Disconnected all slots connected to fSocket";
else
qDebug()<<"failed to disconnected all slots connected to fSocket";
SocketPointerStruct socketPointerStruct;
socketPointerStruct.fSocketPointer = fSocket;
socketPointerStruct.fAutomaticLoginAttempt = automaticLoginAttempts;
fSocket->moveToThread(entry.Connection()->thread());
QMetaObject::invokeMethod(entry.
Connection(),
"SetSocket", Qt
::BlockingQueuedConnection, Q_ARG
(SocketPointerStruct, socketPointerStruct
));
qDebug()<<"User is repatriated";
/* Set entry's connection's socket to this guys socket */
fSocket = NULL;
emit ended(this);
qDebug()<<"User was logged in earlier, now in disconnected mode, a repatriation attempt will be made";
bool tempFlag = fSocket->disconnect();
if(tempFlag)
qDebug()<<"Disconnected all slots connected to fSocket";
else
qDebug()<<"failed to disconnected all slots connected to fSocket";
SocketPointerStruct socketPointerStruct;
socketPointerStruct.fSocketPointer = fSocket;
socketPointerStruct.fAutomaticLoginAttempt = automaticLoginAttempts;
fSocket->moveToThread(entry.Connection()->thread());
QMetaObject::invokeMethod(entry.Connection(), "SetSocket", Qt::BlockingQueuedConnection, Q_ARG(SocketPointerStruct, socketPointerStruct));
qDebug()<<"User is repatriated";
/* Set entry's connection's socket to this guys socket */
fSocket = NULL;
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
Bookmarks