In testing my chat client I took the server offline so that I could work on the handling of queuing messages to be sent when the server is unreachable.
What I found out is that if you make multiple calls to SendHTTPRequestAsync and there's no server response then the program locks up for a bit of time dependent on how many calls you've made. If you make more than one call to SendHTTPRequestAsync to an nonworking server then when you go to exit the program it also hangs a bit.
If anyone would be able to see if the below code acts similar, I'd be appreciative:
dim cid[100]
sync()
for i = 1 to 2
out$ = ConnectToHostAndSendRequest("a" , "b" , 0)
cid[i] = val(GetStringToken(out$ , "," , 1))
Print(GetStringToken(out$ , "," , 2))
next i
sync()
sleep(5000)
repeat
sync()
until GetRawKeyPressed(27) = 1
for j = 1 to 2
CloseHTTPConnection(cid[j])
DeleteHTTPConnection(cid[j])
next j
END
function ConnectToHostAndSendRequest(sPage$ , sData$ , iState)
// Output is stored in a comma separated string
// and must be delimited to be used properly
if GetInternetState() = 1
connectionID = CreateHTTPConnection()
SetHTTPHost(connectionID, "0" , 0 )
iState = SendHTTPRequestASync(connectionID , sPage$ , sData$)
else
if iState < 1
Message("No internet connection")
iState = 1
endif
endif
output$ = str(connectionID) + "," + str(iState)
endfunction output$
Also if anyone has any ideas on how to deal with this I'd appreciate it too. I'm thinking that I might need to send an initial request to the server to see if I get a response and then I can proceed with opening and sending a message, however, this is far from ideal since at anytime the server could go down and I'd literally have to check every time before a message is sent. That sort of destroys the asynchronous transfer. Basically, my chat client would read the chat log at launch and put a message in any array of messages being sent with the above function. So if you have 10 unsent messages the pipeline immediately clogs next time the log is read if the server is down. It seems to me that better handling of the async request by AppGameKit might be in order.
What do you folks think?