Concatenated URLConnection.Send

I am trying to concatenate URLConnection.Send’s.

I’ve made a Subclass of URLConnection and added Methods for various (PUT,GET,POST) Tasks.
In the ContentReceived Event of my Subclass i am checking the HTTPStatus and the content and as a result, may call then another Method within my Subclass which in turn do a Send again.

But i get always a “A request is already in progress” exception. I thought the ContentReceived Event will fire when the content has been received and i can do a new Send?

I would be that there’s a flag that gets unset after the event. However, for reliability it has been recommended multiple times to not re-use a socket. If necessary I build a queuing system with a module.

You probably need the ContentReceived event to actually finish before you can call Send again. Maybe try using a Timer to kick off the Send instead?

I know, but sometimes it makes sense for various reasons. But you just need to be extra carefull. :wink:

I’ll try it. Tried to avoid the extra overhead until now. :slight_smile:

In my opinion, to be extra careful you would create a new socket and request and add it to the queue.

But each new Socket would need to connect and re-authenticate, or? Could be getting slow with 8.000 POST’s. :smiley:

@Paul Lefebvre : Thank you. That did it! :slight_smile:

I added a Xojo.Core.Timer Private Property called SocketTimer to the Subclassed Socket.
Then added a sender As Xojo.Core.Timer as Parameter to my Methods.

Now i can Do a

SocketTimer = New Xojo.Core.Timer SocketTimer.Mode = Xojo.Core.Timer.Modes.Single SocketTimer.Period 250 // Needs tuning... AddHandler SocketTimer, AddressOf myMethodName

What kind of authentication? The don’t re-use sockets note comes from engineer posts on the forum :confused:

Currently only Basic (Name/Password) auth. But will be certificate secured when the servers go live.

I Subclassed a URLConnection which needs to Auth with the Server. And i think each new Socket needs to authenticate before it can communicate with the Server?

In my case, i need to transfer thousands of customers, contacts and Phonenumbers from mySQL Databases to sip:wise Servers using HTTPS and JSON. There can be more than 8.000 Phonenumbers in one App Session needed to be transferred. This would take a few hours (more) if i would have to re-authenticate each “Check if Customer exist, check if Contact exist, Create Contact, Create Customer, Create Subscribers” cycle. :smiley:

Would this, by chance, be a good use-case for a thread and Semaphore?

Thank you @Jonathan Eisen

Maybe, but my current solution works just fine and it’s just a workaround for a Bug in URLConnection which has been fixed for a future release. :slight_smile:

[quote=424648:@Sascha S]Thank you @Jonathan Eisen

Maybe, but my current solution works just fine and it’s just a workaround for a Bug in URLConnection which has been fixed for a future release. :)[/quote]

I saw that you had this all sorted out. I was just wondering if this would work since I have yet to actually use one!

I am sorry to say this but i cannot recommend to use URLConnection in it’s current state. There are more issues other reported in the Feedbacks. But my project is nearly finished and i need to move on. :slight_smile:

If i should recommend a solution i would recommend to use the CURL Addon by MBS. It’s far more capable and issues will be fixed by @Christian Schmitz in very short time.