Engi wrote: > Since I put the code to create an instance of my TWSocketServer and > the > Listen() method in the thread's constructor, all is fine !
In this case the events are not running in worker thread context! Have you tried to initialize worker thread's message queue before the calling listen()? Someting like: procedure TWorkerThread.Execute; var Msg : TMsg; begin PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE); // Initialize thread's message queue Create the instance of TWSocketServer try Assign properties and events Call Listen() Call the message pump finally Destroy instance of TWsocketServer end; end; -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html > > > -----Message d'origine----- > De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > De la > part de Arno Garrels > Envoyé : mardi 10 avril 2007 20:44 > À : ICS support mailing > Objet : Re: [twsocket] Listen exception > > Engi wrote: >> Yes, it is "Error 10022 ..." >> Your comment doesn't exist in my wsocket.pas, but it's the last v5, >> downloaded this morning. > > It is not in v5, it is in current V5/V6 Beta only! > Least work is to add the changes manually then rebuild the package. > It's worth a trial, it won't break anything. > > -- > Arno Garrels [TeamICS] > http://www.overbyte.be/eng/overbyte/teamics.html > >> >> >> -----Message d'origine----- >> De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] >> De la >> part de Arno Garrels >> Envoyé : mardi 10 avril 2007 13:40 >> À : ICS support mailing >> Objet : Re: [twsocket] Listen exception >> >> Engi wrote: >>> Any ideas ? It's a real problem for me . >> >> If the error is NOT "Error 10022 in function WSAASyncSelect", tell us >> the exact line and exception message. >> >> Otherwise, if it is still error 10022 in function WSAASyncSelect, go >> to procedure TCustomWSocket.Listen in WSocket.pas, there should exist >> the following comment: >> >> { FP:26/09/06 Are FD_READ and FD_WRITE really necessary ? >> Probably not ! >> } >> { Lodewijk Ellen reported a problem with W2K3SP1 triggering an AV >> in } >> { accept. Keeping only FD_ACCEPT and FD_CLOSE solved the problem. >> } >> { Anyway, a listening socket doesn't send nor receive any data so >> those } >> { notification are useless. >> } >> >> If not, please either download and install latest V5-Beta or add the >> fix >>> from Lodewijk Ellen manually, even though you see the error in XP >>> SP2. >> >> [..] >> <== // FSelectEvent := FD_READ or FD_WRITE or >> <== // FD_ACCEPT or FD_CLOSE; >> add ==> FSelectEvent := FD_ACCEPT or FD_CLOSE; >> iStatus := WSocket_Synchronized_WSAASyncSelect(FHSocket, >> Handle, >> >> FMsg_WM_ASYNCSELECT, >> >> FSelectEvent); if iStatus <> 0 then begin >> SocketError('WSAASyncSelect'); >> exit; >> end; >> [..] >> >> >> Another small change which is not yet included in current Beta is in >> procedure TCustomWSocket.Dup(): >> >> [..] >> SetLingerOption; >> >> <== // FSelectEvent := FD_READ or FD_WRITE or FD_CLOSE or >> FD_CONNECT; add ==> FSelectEvent := FD_READ or FD_WRITE or FD_CLOSE; >> iStatus := WSocket_Synchronized_WSAASyncSelect(FHSocket, >> Handle, >> >> FMsg_WM_ASYNCSELECT, >> >> FSelectEvent); if iStatus <> 0 then begin >> SocketError('WSAAsyncSelect'); >> Exit; >> end; >> [..] >> >> Please report back whether that helped or not. >> >> -- >> Arno Garrels [TeamICS] >> http://www.overbyte.be/eng/overbyte/teamics.html >> >>> >>> Thanks, >>> Engi >>> >>> -----Message d'origine----- >>> De : [EMAIL PROTECTED] [mailto:twsocket- >>> [EMAIL PROTECTED] De la >>> part de Engi >>> Envoyé : vendredi 6 avril 2007 13:50 >>> À : 'ICS support mailing' >>> Objet : Re: [twsocket] Listen exception >>> >>> >>> Exception at Listen() method >>> >>> -----Message d'origine----- >>> De : [EMAIL PROTECTED] [mailto:twsocket- >>> [EMAIL PROTECTED] De la >>> part de Fastream Technologies Envoyé : vendredi 6 avril 2007 12:59 À >>>> ICS >>> support mailing Objet : Re: [twsocket] Listen exception >>> >>> At which line do you get the exception? >>> >>> ----- Original Message ----- >>> From: "Engi" <[EMAIL PROTECTED]> >>> To: "'ICS support mailing'" <[EMAIL PROTECTED]> >>> Sent: Friday, April 06, 2007 1:11 PM >>> Subject: Re: [twsocket] Listen exception >>> >>> >>> >>> I talked too quickly. >>> I still have errors 10022 from time to time. >>> >>> Here is my code: >>> It is correct ? >>> >>> >>> void __fastcall TThreadWORK::Execute() { try { WSocketServerWORK = >>> new TWSocketServer(NULL); >>> WSocketServerWORK->Proto = "tcp"; >>> WSocketServerWORK->Port = PortIP; >>> WSocketServerWORK->Addr = AdrIP; >>> WSocketServerWORK->LineMode = true; >>> WSocketServerWORK->LineEnd = "\r\n"; >>> WSocketServerWORK->LingerOnOff = wsLingerOn; LingerTimeout = 5000; >>> WSocketServerWORK->ClientClass = >>> __classid(TTcpSrvClientWork); >>> WSocketServerWORK->Banner = ""; >>> WSocketServerWORK->OnClientConnect = >>> WSocketServerWORKClientConnect; >>> WSocketServerWORK->OnClientDisconnect = >>> WSocketServerWORKClientDisconnect; >>> } >>> catch(Sysutils::Exception &e) >>> { >>> if (WSocketServerWORK) delete WSocketServerWORK; WSocketServerWORK = >>> NULL; Terminate(); return; } >>> >>> try >>> { >>> WSocketServerWORK->Listen(); >>> } >>> catch(Sysutils::Exception &e) >>> { >>> if (WSocketServerWORK) delete WSocketServerWORK; WSocketServerWORK = >>> NULL; Terminate(); return; } >>> >>> while (!Terminated) >>> { >>> ... >>> } >>> >>> WSocketServerWORK->ShutDown(0); >>> delete WSocketServerWORK; >>> } >>> >>> >>> >>> >>> -----Message d'origine----- >>> De : [EMAIL PROTECTED] [mailto:twsocket- >>> [EMAIL PROTECTED] De la >>> part de Engi Envoyé : mercredi 4 avril 2007 14:27 À : 'ICS support >>> mailing' >>> Objet : Re: [twsocket] Listen exception >>> >>> >>> Francois, >>> >>> Thanks for this explanations. >>> I moved all the lines from constructor to Execute() method and all >>> is fine now. >>> >>> Engi >>> >>> -----Message d'origine----- >>> De : [EMAIL PROTECTED] [mailto:twsocket- >>> [EMAIL PROTECTED] De la >>> part de Francois Piette Envoyé : mercredi 4 avril 2007 13:15 À : ICS >>> support mailing Objet : Re: [twsocket] Listen exception >>> >>>> No, I create the instance in the thread constructor. >>> >>> Any constructor for TThread class is executed in the context of the >>> creating [likely main] thread, not the [future] created thread ! The >>> new thread context exists only at the very beginning of the Execute >>> method. So you must create any event-driven message based component >>> from the Execute method or their events will run in the creating >>> [main] thread and cause lot's of trouble when you access the >>> component from the context of the created thread. >>> >>> The execution context [thread context] has nothing to do with the >>> fact that the executed code is part or not of the TThread class. It >>> is only related if TThread.Execute is in the call stack. This is a >>> frequent error for newbies in multithreading. >>> >>>> Must I create instance in Execute method >>> >>> Yes, you have. >>> >>>> or deplace listening method in constructor ? >>> >>> You must too, or in any function/procedure called directly or >>> indirectly >>>> from the Execute method. That is you have the Execute method in the >>>> call >>> stack. >>> >>> >>> If you are unsure about the thread context a given function is run, >>> you may call GetCurrentThreadID and compare with the value f the >>> same function called at the very beginning of the Execute method. >>> >>> Contribute to the SSL Effort. Visit >>> http://www.overbyte.be/eng/ssl.html >>> -- >>> [EMAIL PROTECTED] >>> Author of ICS (Internet Component Suite, freeware) Author of MidWare >>> (Multi-tier framework, freeware) 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 >>> >>> -- >>> 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 >>> >>> -- >>> 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 >> -- >> 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 -- 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