Jump to content
merijnb

how to detect when websocket is unable to connect

Recommended Posts

Hello all,

 

I'm using a TSslWebSocketCli and I'm currently testing what happens when the websocket connection cannot be created.
I can use a situation where the server has a maximum number of connections allowed.

See this snippet:

 fWSClient := TSslWebSocketCli.Create(nil);
 fWSClient.OnWSConnected := WSConnected;
 fWSClient.OnWSDisconnected := WSDisconnected;
 fWSClient.OnWSFrameRcvd := WSFrameRcvd;
 fWSClient.OnHTTPRestProg := WSHTTPRestProg;
 fWSClient.OnRestRequestDone := WSHTTPRequestDone;

 // ...

 fWSClient.URL := 'someurl';
 fWSClient.WSConnect(true);  // True = async

When making this connection, I get log through the OnHTTPRestProg event saying: " Request completed: 503 Number of active WebSocket requests has reached the maximum concurrent WebSocket requests allowed."

However, I don't see how I properly detect this issue is going on. OnWSConnected and OnWSDisconnected aren't called in this case. I do get OnRetRequestDone, but it doesn't contain the error code (503).

What is the best way to detect this is going on?

Share this post


Link to post

Hmm, I just found this comment on this thread
 

Quote

A failed connection should give a 404 response, but it not really specified as part of the HTTP protocol.   I am adding new features to the component this week, so will try and test the error handling. 

Are these changes related to my question?

Share this post


Link to post

A quick look at the code suggests some error handling got lost in V9,.5 due to changes to support async mode and to handle data being received before the connected event is called.  

 

I'll need to revisit to make sure OnWS(Dis)Connected is called on failure, or something similar.  

 

The main WebSocket test sample is IcsAppMonMan.dproj which I updated for async and runs 24/7 here monitoring my servers as they come and go, so you can check what error handling I used.  The sample should access some of my own Websocket servers. 

 

Angus

 

  • Like 1

Share this post


Link to post

This problem should be fixed in SVN, so WSConnect failures now trigger the OnWSConnected event, check IsWSConnected for success.  Please test, sounds like you were doing more extensive testing than I did.  

 

Angus

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×