Re: [twsocket] still problems with terminating the socket
Hello Markus, Okay, exception can be ruled out, the shutdown call is within try / except and I have a output in the except clause showing the exception. This doesn't fire. There is something wrong that we cannot see. Consider one of your previous mails: - output a debug message to eventlog - socket.shutdown(1); - output a 2nd message to eventlog But: it doesn't even get to the 2nd message! Unless ShutDown has a deadlock the 2nd message should get called. So there could be a problem with the sending of message to windows event log. Maybe the class you use also does need a message pump ? I suggest to try it simple: AllocConsole;// somewhere in dll initialisation try WriteLn('first message'); Socket.ShutDown(1); WriteLn('second message'); except on E: Exception do WriteLn(E.Message); end; Can you tell the result please ? --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz Friday, February 3, 2006, 08:40, Humm, Markus wrote: Hello, Hello Markus, I put some debug output in my OnSessionCLosed handler, it doesn't seem to be called. But I haven't yet debugged. See my other reply. If it is not fired, then eather ShutDown did not work because of some exception error, or eather the message pump of the thread where TWSocket is created or attached to is not pumping. Okay, exception can be ruled out, the shutdown call is within try / except and I have a output in the except clause showing the exception. This doesn't fire. Another thought: the dll has a seperate thread only for message pumping for all used components within the dll. What if I would assign all sockets to this thread after creation? e.g. assign the sockets to this thread when they're created and give the thread a method for closing these sockets. Could this solve my problems? Greetings Markus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] still problems with terminating the socket
Hello, after moving the creation of the sockets in the execute method of the thread which sends and initiates the closing of the communication channel the thing closed like a charm! Now there is only the problem if the communication doesn't close and the communication dll tries to close the still open connection. Greetings Markus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] still problems with terminating the socket
Hello Markus, Okay, exception can be ruled out, the shutdown call is within try / except and I have a output in the except clause showing the exception. This doesn't fire. There is something wrong that we cannot see. Consider one of your previous mails: - output a debug message to eventlog - socket.shutdown(1); - output a 2nd message to eventlog But: it doesn't even get to the 2nd message! Unless ShutDown has a deadlock the 2nd message should get called. So there could be a problem with the sending of message to windows event log. Maybe the class you use also does need a message pump ? I suggest to try it simple: AllocConsole;// somewhere in dll initialisation try WriteLn('first message'); Socket.ShutDown(1); WriteLn('second message'); except on E: Exception do WriteLn(E.Message); end; Can you tell the result please ? The debugger didn't reach that point as well! And in the OnSessionClosed the output is done via writing into a textfile which is created there if it works. But the file never gets created. It seems that moving the creation of the Socket to the right thread helped, it doen't hang now anymore, but since the OnSessionCLosed doesn't occur, there still seems to be a problem. How would I implement a good message pump in that thread? It's execute method does just check wheter there is something to send and if yes, it will build a correct data packet and send it. Then it will be idle until the next send request comes in. Greetings Markus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] still problems with terminating the socket
Or better try something like this (not tested) procedure TMyThread.Execute; begin prepare the data to be sent Wsocket := TWsocket.Create(nil); try Assign all properties and events .. Wsocket.Send(something); Wsocket.MessageLoop; finally WSocket.Free; WSocket := nil; clean up, thread result etc. if necessary end; end; procedure TMyThread.WSocketDataSent(Sender: TObject; ErrCode: Word); begin WSocket.CloseDelayed; end; procedure TMyThread.WSocketSessionClosed(Sender: TObject; ErrCode: Word); begin PostMessage(WSocket.Handle, WM_QUIT, 0, 0); end; It's execute method does just check wheter there is something to send and if yes, it will build a correct data packet and send it. Then it will be idle until the next send request comes in. Greetings Markus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] still problems with terminating the socket
Hello Markus, Seems you don't get the Event-driven way of programming, why a loop of 100ms that seems to do nothing with event it could receive ? HM - output a debug message to eventlog HM - socket.shutdown(1); HM - output a 2nd message to eventlog HM - do this: HM t:=GetTickCount; HM while (GetTickCount-t 100) do HM begin HM TranslateMessage(MsgRec); HM DispatchMessage(MsgRec); HM WaitMessage; HM end; HM - output a 3rd message to eventlog HM - Socket.Release; HM But: it doesn't even get to the 2nd message! HM I will put a message in my OnSessionClosed event as well. HM But I don't know why the 2nd message (and all later) aren't written. HM The main program still hangs for some seconds. After that a 2nd click on HM close can be done which works then (at least closes the app.) HM Greetings HM Markus Humm -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] still problems with terminating the socket
HM while (GetTickCount-t 100) do HM begin HM TranslateMessage(MsgRec); HM DispatchMessage(MsgRec); HM WaitMessage; HM end; This doesn't look like a proper message loop. Waiting 100mS for shutdown to complete is probably much much too short ! -- [EMAIL PROTECTED] http://www.overbyte.be - Original Message - From: Humm, Markus [EMAIL PROTECTED] To: ICS support mailing twsocket@elists.org Sent: Thursday, February 02, 2006 2:24 PM Subject: Re: [twsocket] still problems with terminating the socket Hello Markus, Seems you don't get the Event-driven way of programming, why a loop of 100ms that seems to do nothing with event it could receive ? HM - output a debug message to eventlog HM - socket.shutdown(1); HM - output a 2nd message to eventlog HM - do this: HM t:=GetTickCount; HM while (GetTickCount-t 100) do HM begin HM TranslateMessage(MsgRec); HM DispatchMessage(MsgRec); HM WaitMessage; HM end; HM - output a 3rd message to eventlog HM - Socket.Release; HM But: it doesn't even get to the 2nd message! HM I will put a message in my OnSessionClosed event as well. I did that on some recommendation, because the OnSessionClosed might not occur so nobody would release the socket then. So I'm waiting that 100ms to release that socket if not already done. (okay this is not yet correct here but he doesn't come to that line yet so it doesn't matter just now.) He doesn't seem to fire OnSessionClosed! He seems to hand at the socket.shutdown call. I will check next the thread ids as recommendet by somebody else. Greetings Markus -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] still problems with terminating the socket
thanks for clarification. It doesn't matter that the one thread which communicates via TWSocket doesn't reside in the same DLL as the TWSocket created? A thread is not located in a DLL or in an exe. A thread is independent on where the code is ! Putting a method into a TThread class doesn't mean it is executed by the thread ! A thread is a context of execution and has nothing to do with where the code is defined. The only thing almost sure is that TThread.Execute is executed in the thread's context. Any code elseware, including code defined as a TThread's method, may or may not be executed in the thread context. -- Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] still problems with terminating the socket
Hello Markus, I will check next the thread ids as recommendet by somebody else. Also you need to check if the message pump is working in the right thread context. So you best check over there too. This because you mention that OnClose is never fired. I think I forgot to say that in my previous reply. --- Rgds, Wilfried [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html http://www.mestdagh.biz -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be