[twsocket] Client identification
Hi, In my program, a TWSocketServer in thread 'A' receives commands (queries) from clients. The thread 'A' post this commands to another thread 'B' which execute them. Later, thread A receives an asynchronous answer from thread 'B'. How can the thread A could transmits this answer to the good client (the one which send query) ? Is there unik identifier for each client IP ? Engi -- 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] Listen exception
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)
Re: [twsocket] Client identification
OK, thanks. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Arno Garrels Sent: Friday, April 13, 2007 11:20 AM To: ICS support mailing Subject: Re: [twsocket] Client identification Engi wrote: Hi, In my program, a TWSocketServer in thread 'A' receives commands (queries) from clients. The thread 'A' post this commands to another thread 'B' which execute them. Later, thread A receives an asynchronous answer from thread 'B'. How can the thread A could transmits this answer to the good client (the one which send query) ? Is there unik identifier for each client IP ? You can use the object reference or the Sender to identify client objects. Before sending the answer check if the client is still in the client list, AND also don't forget to identify each client thru a unique, custom ID since the same address _may already be assigned to a newly connected client if the destination client has disconnected while the thread processed the task. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -- 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] Listen exception
Yes, I have tried to initialize worker thread's message queue before the calling listen(), but no effect ! -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Arno Garrels Sent: Friday, April 13, 2007 11:01 AM To: ICS support mailing Subject: Re: [twsocket] Listen exception 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; -- 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
[twsocket] Client close exception and connection doubt
Hello all, I want to discuss an architectural issue here I´m debugging an application of mine and yesterday it has stopped working and I got the following EurekaLog call stak information |00507C4D|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |RaiseException|2009[4] | |0050D08B|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |SocketError |7045[17] | |0050CFD8|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |SocketError |7028[0] | |0050CBD1|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |InternalClose |6672[34] | |0050CACF|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |Close |6589[1] | |0050939A|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |Destroy |4303[8] | |00509348|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |Destroy |4295[0] | |0050F4E3|Servidor.exe|OverByteICSWSocket.pas|TCustomLineWSocket |Destroy |8104[11] | |7C91503E|ntdll.dll | | |bsearch | | |7E36A03E|USER32.dll | | |ClientThreadSetup | | |7C90EAF5|ntdll.dll | | |KiUserApcDispatcher | | |7E369239|USER32.dll | | |CharUpperBuffW| | |7E36AEBF|USER32.dll | | |CharUpperBuffA| | |7E36AEE3|USER32.dll | | |CharUpperBuffA| | |7C90E21D|ntdll.dll | | |ZwQueryVirtualMemory | | |7C80B9B7|kernel32.dll| | |VirtualQueryEx| | |7C80B9A0|kernel32.dll| | |VirtualQueryEx| | |7C80B9E1|kernel32.dll| | |VirtualQuery | | |7C80B9D1|kernel32.dll| | |VirtualQuery | | |00509286|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |Create|4271[6] | |00509230|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |Create|4265[0] | |0050DEC6|Servidor.exe|OverByteICSWSocket.pas|TCustomSocksWSocket |Create|7254[1] | |0050DEB0|Servidor.exe|OverByteICSWSocket.pas|TCustomSocksWSocket |Create|7253[0] | |0050F45E|Servidor.exe|OverByteICSWSocket.pas|TCustomLineWSocket |Create|8084[1] | |0050F448|Servidor.exe|OverByteICSWSocket.pas|TCustomLineWSocket |Create|8083[0] | |00534F14|Servidor.exe|UTDriverCommSocketThread.pas |TDriverCommSocketThread |Execute |355[11] | |7C90E57A|ntdll.dll | | |NtSetEvent| | |7C80A021|kernel32.dll| | |SetEvent | | |7C80A017|kernel32.dll| | |SetEvent | | I have seen on OverByteICSWSocket.pas InternalClose on line 6672 it raises that exception only when ICS is used on DLL, but that is not my case Actually I thing that this exception was raised because of the architecture of my software and I need an opinion about that. My software is a service application that can have several TWSocket clients to get live video data from different sources. Each instance of TWSocket is working on a different thread. Apparently my application doesn´t work very well when some hosts are down, it frequently shuts the service down, but this happens only when I have some hosts down. My app has a Timeout parameter (Default 4 seconds) when if it doesn´t receives video from the host it closes the connection and opens it again, I think that I´m having some problems on this timeout concept, so, for example if I have 5 down hosts, at each 4 seconds my app will try to connect to this host, and I don´t know why, it is compromising my app stability I have tried to
Re: [twsocket] Client close exception and connection doubt
Éric, Since ICS works asynchronous a reconnect-timer should be started from event handler OnSessionClosed, is that the case? Also the best place to destroy the object is from OnSessionClosed as well. But the OnSessionClosed event will be triggered if I try to connect to an inacessible host? I think that my actual reconnect-timer is bugged, because lets imagine that I call the connect routine to make a connection, if the host is unavailable it will take some time to return me a connection error event right? And this time is more than 4 seconds.. but on my actual implementation I wait just 4 seconds before trying to open the connection again, and I don´t know if this can mess with windows TCP implementation Éric -- 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
[twsocket] Bug in HTTPProt.pas (URGENT)
Hello, Please use the ICS http prot demo to locate to an Apache with 401 protection with chunked mode: Not using proxy cmd GET / HTTP/1.1 cmd Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */* cmd Connection: Keep-Alive cmd Accept-Language: en, fr cmd User-Agent: Mozilla/3.0 (compatible) cmd Host: www.fastream.com cmd RequestDone, no error. Status =401 StatusCode = 401 hdrHTTP/1.1 401 Authorization Required hdrDate: Fri, 13 Apr 2007 14:34:00 GMT hdrServer: Apache/1.3.29 (Unix) FrontPage/5.0.2.2623 hdrWWW-Authenticate: Basic realm=type your yser name password hdrConnection: close hdrTransfer-Encoding: chunked hdrContent-Type: text/html; charset=iso-8859-1 hdr1d6 hdr!DOCTYPE HTML PUBLIC -//IETF//DTD HTML 2.0//EN hdrHTMLHEAD hdrTITLE401 Authorization Required/TITLE hdr/HEADBODY hdrH1Authorization Required/H1 hdrThis server could not verify that you hdrare authorized to access the document hdrrequested. Either you supplied the wrong hdrcredentials (e.g., bad password), or your hdrbrowser doesn't understand how to supply hdrthe credentials required.P hdrHR hdrADDRESSApache/1.3.29 Server at www.fastream.com Port 80/ADDRESS hdr/BODY/HTML hdr0 Notice that this page is mistakenly a 401 and will become 200 soon. So BE QUICK or setup your own Apache. Regards, SZ -- 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] Client close exception and connection doubt
Éric Fleming Bonilha wrote: Éric, Since ICS works asynchronous a reconnect-timer should be started from event handler OnSessionClosed, is that the case? Also the best place to destroy the object is from OnSessionClosed as well. But the OnSessionClosed event will be triggered if I try to connect to an inacessible host? Yes, after Connect executed without an exception (better wrap Connect in a try except block) OnSessionConnected as well as OnSessionClosed will fire, the error passed to OnSessionConnected may be helpfull. I think that my actual reconnect-timer is bugged, because lets imagine that I call the connect routine to make a connection, if the host is unavailable it will take some time to return me a connection error event right? And this time is more than 4 seconds.. but on my actual implementation I wait just 4 seconds before trying to open the connection again, and I don´t know if this can mess with windows TCP implementation You have to call Abort once Connect has been called and OnSessionClosed has not been triggered yet to abort the session. Then in OnSessionClosed start the timer or post a custom message if you want to reconnect at once. Éric -- 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] Client close exception and connection doubt
Hello Éric, Actually I thing that this exception was raised because of the architecture of my software and I need an opinion about that. What is exacly the exception message ? when I have some hosts down. My app has a Timeout parameter (Default 4 seconds) when if it doesn´t receives video from the host it closes the connection and opens it again You have to call Close (or CloseDelayed), and in OnSessionClosed you post a message to custom message handler where you connect again. I have tried to do this reconnect to the host by 2 ways, by Closing and Opening the TWSocket connection again and by Destroying and Creating a new TWSocket component each time it needs to reconnect to the host (at each 4 seconds) Both are good. Closing / opening will be the most preferabel in my opinion. on the first way (Closing and Opening) I got some EOutOfMemory error on ICS Is it 'no buffer space available' ? Because Windows keep the socket for a while after closing the connection (I think 2 minute). Sockets are made into the non paged memory pool which stop growing at 1/8 the size of physical RAM. So with the amount of sockets in TIME_WAIT state + the sockets you create it could be that you run out of memory ? Consider that a socket takes around 2 KB, and that overlapped IO (used by winsock) eat also in blocks of 4 KB. and on this second way (Destroying and Creating the TWSocket component) I got that exception message at the beggining of the email. I cannot see the exact exception message. Can you give it ? Can you tell me if this reconnection procedure that I made (each 4 seconds for down hosts) is dangerous to TCP at any way? Definitively not. But possible you have a memory problem because of the TIME_WAIT sockets (nothing to do with ICS, but that's how winsock works). Another thing that I have thinked is that if I need to wait the TWSocket connection error message before trying to reconnect to the host or I can close if before receiving the error message? Use OnSessionClosed. But do not reconnect from within the event handler, but post a custom message so that the reconnect is outside the event. --- 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
Re: [twsocket] Client close exception and connection doubt
You have to call Abort once Connect has been called and OnSessionClosed has not been triggered yet to abort the session. Then in OnSessionClosed start the timer or post a custom message if you want to reconnect at once. Ok, now I undestood, I will try to implement on that way Thank you Arno! Éric -- 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] Client close exception and connection doubt
Hello Wilfried, What is exacly the exception message ? The exception that was raised was Socket operation on non-socket (#10038 in Disconnect (closesocket)). and it was raised on this: |00507C4D|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |RaiseException|2009[4] | |0050D08B|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |SocketError |7045[17] | |0050CFD8|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |SocketError |7028[0] | |0050CBD1|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |InternalClose |6672[34] | |0050CACF|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |Close |6589[1] | |0050939A|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |Destroy |4303[8] | |00509348|Servidor.exe|OverByteICSWSocket.pas|TCustomWSocket |Destroy |4295[0] | |0050F4E3|Servidor.exe|OverByteICSWSocket.pas|TCustomLineWSocket |Destroy |8104[11] | This is the call stack that was created by EurekaLog. The exception was raised when I was trying to free the TWSocket component, see the call stack, first the Destroy of TCustomLineeWSocket is called, and see when TCustomWSocket calls the Close routine, it calls the InternalClose that raises the exception. You have to call Close (or CloseDelayed), and in OnSessionClosed you post a message to custom message handler where you connect again. I will try to do that way, sending a custom message to make a reconnection Is it 'no buffer space available' ? Because Windows keep the socket for a while after closing the connection (I think 2 minute). Sockets are made into the non paged memory pool which stop growing at 1/8 the size of physical RAM. So with the amount of sockets in TIME_WAIT state + the sockets you create it could be that you run out of memory ? Consider that a socket takes around 2 KB, and that overlapped IO (used by winsock) eat also in blocks of 4 KB. Actually I don´t remember very well why it raised this EOutOfMemory exception, I will try to reproduce it once again and see where is raises Definitively not. But possible you have a memory problem because of the TIME_WAIT sockets (nothing to do with ICS, but that's how winsock works). I´m a little affraid of this TIME_WAIT sockets :) As I said on my last e-mail, one day I have made one test and I left my software trying to get video from 20 different inacessible hosts, I left it by night, and when I came to see on the morning the whole windows tcp/ip was inoperant, Firefox, Internet Explorer was not working and neither the windows network, I coulnd´t even ping any machine on my network. Do you know why this could have happened? Considering that mny software was doing that reconnect procedure for all hosts. Use OnSessionClosed. But do not reconnect from within the event handler, but post a custom message so that the reconnect is outside the event. Thanks I will try to implement on that way, Arno also gave me the same advice --- 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 -- 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] Listen exception
Engi wrote: Yes, I have tried to initialize worker thread's message queue before the calling listen(), but no effect ! I'm sorry, this was my last idea, especially _if you added the changes I posted in one of my previous messages. I never saw a socket error in WSAASyncSelect in one of my applications so far. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Arno Garrels Sent: Friday, April 13, 2007 11:01 AM To: ICS support mailing Subject: Re: [twsocket] Listen exception 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; -- 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] Listen exception
Thank you very much for your help. Perhaps a bad construction of my source code. I'll try to rewrite this later. Bye, Engi -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Arno Garrels Sent: Friday, April 13, 2007 7:27 PM To: ICS support mailing Subject: Re: [twsocket] Listen exception Engi wrote: Yes, I have tried to initialize worker thread's message queue before the calling listen(), but no effect ! I'm sorry, this was my last idea, especially _if you added the changes I posted in one of my previous messages. I never saw a socket error in WSAASyncSelect in one of my applications so far. -- Arno Garrels [TeamICS] http://www.overbyte.be/eng/overbyte/teamics.html -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Arno Garrels Sent: Friday, April 13, 2007 11:01 AM To: ICS support mailing Subject: Re: [twsocket] Listen exception 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; -- 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