Title: TRtcHttpClient.OnConnect always called after TRtcDataRequest.Post()? Post by: DougB on September 09, 2014, 06:15:18 AM It seems that even if a TRtcHttpClient is already connected to the server, calling TRtcDataRequest.Post() will cause the OnConnect event to be fired for every message that is sent over the open connection. I need to know when the client has been connected only once (to update my active connection counter and perform a few other tasks). Multiple calls to OnConnect when the client is already connected is somewhat confusing... Is there another way to get notified of a successful connection only once?
Thanks, Doug Title: Re: TRtcHttpClient.OnConnect always called after TRtcDataRequest.Post()? Post by: D.Tkalcec (RTC) on September 09, 2014, 08:43:41 AM When using a connection-based API like WinSock, the OnConnect event is called when a connection has just been established. But when using the WinInet or WinHTTP API (set useProxy=True or useWinHTTP=True) on Windows, which do not have a concept of opening or closing physical connections (it has a concept of requests instead), the OnConnect event is called every time the low-level API objects have been initialized for use, to emulate the behavior of connection-based APIs, even though no physical connection is being established at that time. Because WinInet and WinHTTP APIs do not have a concept of physical connections, if you want your code to work with all supported APIs, you should set the AutoConnect and ReconnectOn properties of the TRtcHttpClient component to TRUE and only worry about requests and responses, but not about physical connections.
Based on your statement, I can only assume that you were using the WinInet or WinHTTP APIs (the useProxy or the useWinHTTP property was set to TRUE), or that the Server you were testing the code with has been closing the connection. Some Servers will close a connection immediately after sending a response, while other Servers have time-out periods to close idle connections. If a Server closes its side of a connection, there is nothing a Client can do about it, except opening a new connection before sending a new request. In short, I can not recommend writing code which relies on the connection-specific events. These events may be useful for statistical purposes, but they are not a reliable way of knowing when a physical connection is really being open or closed, unless you are using a connection-based API like WinSock. Best Regards, Danijel Tkalcec Title: Re: TRtcHttpClient.OnConnect always called after TRtcDataRequest.Post()? Post by: DougB on September 09, 2014, 04:02:40 PM I am using Winsock, and the connections are persistent (the server doesn't disconnect them).
I have no intention of setting useProxy or useWinHTTP, as I want to use asynchronous sockets. Unless these settings default to TRUE, there must be another problem (or it just works this way). Thanks, Doug Title: Re: TRtcHttpClient.OnConnect always called after TRtcDataRequest.Post()? Post by: D.Tkalcec (RTC) on September 09, 2014, 04:37:09 PM When using WinSock, the OnConnect event will only be called once when a connection has just been opened. If you are receiving multile OnConnect events when using WinSock, it can only mean that the connection was closed and needed to be opened again for a new request to be posted.
Best Regards, Danijel Tkalcec Title: Re: TRtcHttpClient.OnConnect always called after TRtcDataRequest.Post()? Post by: DougB on September 10, 2014, 03:48:17 AM Thanks, you are right. There was another problem with my code, so it works as expected. ;)
Doug |