Xojo.Net.HTTPSocket Disconnect

If you have an instance of this socket on a window and invoke an async operation but then close the window before the operation has completed (PageReceived event) will this cause an error and as such should you call Disconnect on the cance buttonl/window close event?

Also, what happens if you call Disconnect on a socket that is not connected anymore? Will it throw an error?

Nothing should happen… Give it a try to see…

Well I ran a few tests on a custom subclass of the socket and basically nothing happens if you disconnect a socket that has not been initiated in any way but if you initiate a request and then close the socket’s window without the async request completing then the class’ PageReceived event raises a NilObjectError if you have raised the event (to the window’s instance of the socket) at the end of the subclass event. To avoid this I’ve just added a “Communicating” boolean property to the subclass and set to true when the request is initiated and false on an Error and PageReceived. Then on the instance’s window close event you can do as follows:

If mySocket.Communicating then mySocket.Disconnect End If