Page 2 of 2
Re: Problems in Windows with HTTP-REST API Skeleton
Posted: Fri Apr 11, 2025 6:59 pm
by jakobssystems
infratec wrote: Fri Apr 11, 2025 6:18 pm
It does not crash here at the CloseConnection() line (WIn10 x64 PB 621b2 x86)
But it crashed once in Select NetworkServerEvent()
So I modified it a bit and then it runs smooth:
Adopted your modification but it still keeps crashing here. The first request/response runs, but then it fails.
I am on 64iBit on Win2019
I've made two Screenshots in Windows:
And one in Wine on GNU/Linux. At least there is more information:

Re: Problems in Windows with HTTP-REST API Skeleton
Posted: Fri Apr 11, 2025 8:00 pm
by infratec
Your PeekS() usage is wrong:
Code: Select all
Header = PeekS(*buffer, headerEndPos, #PB_UTF8)
Body = PeekS(*buffer + headerEndPos + 4, totalReceived - headerEndPos - 4, #PB_UTF8)
Should be:
Code: Select all
Header = PeekS(*buffer, headerEndPos, #PB_UTF8|#PB_ByteLength)
Body = PeekS(*buffer + headerEndPos + 4, totalReceived - headerEndPos - 4, #PB_UTF8|#PB_ByteLength)
also later:
Code: Select all
body + PeekS(*tempBuffer, received, #PB_UTF8|#PB_ByteLength)
And have you enabled the purifier and set the granularity to 1,1,1,1
Re: Problems in Windows with HTTP-REST API Skeleton
Posted: Fri Apr 11, 2025 8:33 pm
by infratec
In general, your handling is wrong.
You don't wait if the client disconnects after all.
You don't wait for further network events of the same client.
You close the network connection directly after sending the Hello. This can be wrong, since the network stack is asynchron,
and I don't know if the send operation is already finished when you close the connection.
You should use a client map and check for each incoming network event if the client is already available or not.
f he sends a disconnect, then close the connection. Or close it after a timeout after the last data received.
Then you don't run in a to early closing.
Re: Problems in Windows with HTTP-REST API Skeleton
Posted: Sat Apr 12, 2025 12:17 am
by idle
you can take a look here, it uses a similar pattern to infratec's suggestion
https://github.com/idle-PB/atomic_webserver_3
look at
https://github.com/idle-PB/atomic_webse ... erver3.pbi
Atomic_Server_Thread
Atomic_Server_ProcessRequest
There's rather a lot going on in the code but you should be able to find the salient bits and how it's handling it.
[/code]
Re: Problems in Windows with HTTP-REST API Skeleton
Posted: Sun Apr 13, 2025 12:07 pm
by jakobssystems
First thank you all for your input.. right now i am rewriting my thread handling this weekend... so please give some time to answer.
Re: Problems in Windows with HTTP-REST API Skeleton
Posted: Sun Apr 13, 2025 8:36 pm
by jakobssystems
Update: Windows version is up and running after a partial rewrite of the Threadmodel.
Thank you @infrate, you pushed me into the right Direction.
And @idle I took a peek into the Atomic Webserver but this is directly using the Socket in Windows. It tries to be a fully blown Webserver and has a lot of dependencies. My aim is different. I want a minimalistic REST API Server, a single-exeecutable.