A brand new game
for Windows, HTML5, 3DS Homebrew, iPhone, Android TV and more,
6th December, 2017
After a day spent trying to track down the issue(s), I've finally got WinSock to return exactly what I expect it to return!
I can't rest yet, as I need to foolproof the values being returned, and also then get it working on things other than Windows...
WinSock is strictly for Windows, so .. It's going to be a system-by-system rewrite to get everything on the same level.
But I'm about 50% confident that I'm able to send requests from the Windows editions of the games.
*sigh* That took a while!!
Pitfalls whilst trying to get this to work.
1. The standard recv() thing doesn't add a \0 string termination thing to the end of the received string, so all that weird repetition I was seeing was due to that. A simple ReturnedString+='\0' helped, there.
2. Apparently "Chunked" is a standard server thing. I never knew! Rather than sending just the reply, the server sends the length of a string, then the string.. .. then another string in the same way.. then another, and another, and so on..
This might seem obvious, but the chunks it was sending were within more chunks. It's like a chunk-ception in that I had to read "This chunk", then check for chunks within those chunks!!
3. '\r\n' A particularly tricky thing, as you need to be able to read the \r\n newline commands, because your output might need to include that. But at the same time, you need to ignore the \r\n newlines that wrap around the string based values of the chunk lengths!
I needed to read the chunk, extract the sub-chunk length, ignore the newline, extract the sub-chunk, then check that the chunk had any more sub-chunks before moving on.
.. This all sounds very complicated, and rather convoluted, and trust me when I say it was a right pain in the arse to figure it all out.
But it "appears" to be working.
It might not stand up to stress-testing, but for now it is at least sending and receiving in a way that looks like it's not completely broken!!