RTC Forums
April 29, 2024, 12:50:43 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: TRtcHttpClient.OnConnect always called after TRtcDataRequest.Post()?  (Read 3638 times)
DougB
Newbie
*
Posts: 19


« 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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 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
Logged
DougB
Newbie
*
Posts: 19


« Reply #2 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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 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
Logged
DougB
Newbie
*
Posts: 19


« Reply #4 on: September 10, 2014, 03:48:17 AM »

Thanks, you are right.  There was another problem with my code, so it works as expected. Wink

Doug
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 17 queries.