atomic web server threads
Re: atomic web server threads
I didn't put any mutex in this example but I'm using them in my program.
A mutex for the SendNetworkString() is this example wouldn't fix the problem (there is only one Send and no competitive access).
A mutex for the SendNetworkString() is this example wouldn't fix the problem (there is only one Send and no competitive access).
Windows 11 Pro x64
PureBasic 6.30 x64
PureBasic 6.30 x64
Re: atomic web server threads
I'll take a look in the morning if I get time.
Re: atomic web server threads
I don't see any issue with your test example on windows PB6.30 x64. The send in the thread doesn't crash it
Re: atomic web server threads
At the first start of the server there is no crash, SendNetworkString() return -1. But if you retry (stop/start the server), you should have a crash.
I'm not using TLS.
I'm not using TLS.
Windows 11 Pro x64
PureBasic 6.30 x64
PureBasic 6.30 x64
Re: atomic web server threads
I can't get it to crash at all.tatanas wrote: Thu Jan 29, 2026 7:59 am At the first start of the server there is no crash, SendNetworkString() return -1. But if you retry (stop/start the server), you should have a crash.
I'm not using TLS.
Re: atomic web server threads
HI Idle, I am running your single_server_localhost example, adjusted my hosts file to have 127.0.0.1 and I can see the site on all of the browsers on this computer.
Should I be able to see the web site on my mobile phone which is also registered on the same wifi network?
Should I be able to see the web site on my mobile phone which is also registered on the same wifi network?
Re: atomic web server threads
not via 127.0.0.1 of course.
You need to call the network ip
You need to call the network ip
{Home}.:|:.{Dialog Design0R}.:|:.{Codes}.:|:.{History Viewer Online}.:|:.{Send a Beer}
Re: atomic web server threads
Yes, of course. Should I have anything special in 'hosts' for that?
I am now trying the ip address of the computer I am running the Atomic Web Server on in my mobile phone, and it still doesn't see it.
EDIT: I hadn't updated the IP address in the program. Sorted now thanks.
Re: atomic web server threads
I'm now trying to use this 'single_server_localhost.pb' as a server for a folder on PC to allow me to use .wget to download a file onto ZX Spectrum (with wifi adaptor attached) wirelessly.
The file seems to link okay, but doesn't actually download anything.
The terminal in the program returns "connect 1726160353472
192.168.x.xx GET /drawing.bmp HTTP/1.0 client 1726160353472 time 20:15:57"
The spectrum status just doesn't update until I close the server on PC or until the event times out.
Any ideas what I might have to change to allow the files to upload correctly? I can do this fine on windows IIS.
EDIT: Maybe this 'single_server_localhost.pb" isn't the type of server that I can just upload a file to the www folder, and expect all computers accessing the server to see it? I tried on my mobile phone, and it wasn't able to download it either.
The file seems to link okay, but doesn't actually download anything.
The terminal in the program returns "connect 1726160353472
192.168.x.xx GET /drawing.bmp HTTP/1.0 client 1726160353472 time 20:15:57"
The spectrum status just doesn't update until I close the server on PC or until the event times out.
Any ideas what I might have to change to allow the files to upload correctly? I can do this fine on windows IIS.
EDIT: Maybe this 'single_server_localhost.pb" isn't the type of server that I can just upload a file to the www folder, and expect all computers accessing the server to see it? I tried on my mobile phone, and it wasn't able to download it either.
Last edited by matalog on Fri Feb 20, 2026 10:46 pm, edited 1 time in total.
Re: atomic web server threads
you've replicated the git hub folder on your pc under www folder and your using wget from the zx spectrum to copy the files from your PC as long as it's using http and there's an index with links it should work.matalog wrote: Fri Feb 20, 2026 9:24 pm I'm now trying to use this 'single_server_localhost.pb' as a server for a folder on PC to allow me to use .wget to download a file onto ZX Spectrum (with wifi adaptor attached) wirelessly.
The file seems to link okay, but doesn't actually download anything.
The terminal in the program returns "connect 1726160353472
192.168.x.xx GET /drawing.bmp HTTP/1.0 client 1726160353472 time 20:15:57"
The spectrum status just doesn't update until I close the server on PC or until the event times out.
Any ideas what I might have to change to allow the files to upload correctly? I can do this fine on windows IIS.
EDIT: Maybe this 'single_server_localhost.pb" isn't the type of server that I can just upload a file to the www folder, and expect all computers accessing the server to see it? I tried onmy mobile phone, and it wasn't able to download it either.
atomic won't index or list the files, it will only fetch requested files.
It mentions on the github page you cant use : on in the command http:// is http// is wget adding it back in ?
so the server sees http://
as a sanity check can you see the local files in your web browser on the pc?
Re: atomic web server threads
idle wrote: Fri Feb 20, 2026 10:20 pmyou've replicated the git hub folder on your pc under www folder and your using wget from the zx spectrum to copy the files from your PC as long as it's using http and there's an index with links it should work.matalog wrote: Fri Feb 20, 2026 9:24 pm I'm now trying to use this 'single_server_localhost.pb' as a server for a folder on PC to allow me to use .wget to download a file onto ZX Spectrum (with wifi adaptor attached) wirelessly.
The file seems to link okay, but doesn't actually download anything.
The terminal in the program returns "connect 1726160353472
192.168.x.xx GET /drawing.bmp HTTP/1.0 client 1726160353472 time 20:15:57"
The spectrum status just doesn't update until I close the server on PC or until the event times out.
Any ideas what I might have to change to allow the files to upload correctly? I can do this fine on windows IIS.
EDIT: Maybe this 'single_server_localhost.pb" isn't the type of server that I can just upload a file to the www folder, and expect all computers accessing the server to see it? I tried onmy mobile phone, and it wasn't able to download it either.
atomic won't index or list the files, it will only fetch requested files.
It mentions on the github page you cant use : on in the command http:// is http// is wget adding it back in ?
so the server sees http://
as a sanity check can you see the local files in your web browser on the pc?
I have replicated the github folder on my PC. I added a bmp file to the www folder in that.
How do I index a new file in there? It is telling me that the files I add, that I haven't indexed, are Not found.
I can indeed see other files you use, like index.html on my phone and the local PC.
I can see 192.168.x.xx/images/atomic_webserver6.jpg from my phone, and searching the text of the whole source folder in notepad++, it doesn't seem to be mentioned.
How can I determine what images in the source folders will be available to browsing computers?
Re: atomic web server threads
you can use a handler to do indexof to generate the hrefs of the root
Code: Select all
XIncludeFile "atomic_web_server3.pbi"
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
#Cdir = "\"
CompilerElse
#Cdir = "/"
CompilerEndIf
Structure folderContents
type.b
value.s
EndStructure
Procedure GetFileList(StartDir.s,List Lfiles.folderContents(),pattern.s="*.*",Recursive=1,bset=0)
Protected mDir,Directory.s,Filename.s,FullFileName.s, tdir.s,ct,a,depth,bmatch
Static NewList Lpattern.s()
Static FileCount
If Not bset
StartDir = RTrim(StartDir, #Cdir)
pattern = RemoveString(pattern,"*.")
ct = CountString(pattern,"|") + 1
ClearList(lpattern())
For a = 1 To ct
AddElement(Lpattern())
Lpattern() = UCase(StringField(pattern,a,"|"))
Next
filecount=0
bset=1
EndIf
mDir = ExamineDirectory(#PB_Any, StartDir, "*.*")
If mDir
While NextDirectoryEntry(mDir)
If DirectoryEntryType(mDir) = #PB_DirectoryEntry_File
Directory = startdir
FileName.s = DirectoryEntryName(mDir)
ForEach Lpattern()
If Lpattern() = GetExtensionPart(UCase(Filename))
bmatch=1
ElseIf Lpattern() = "*"
bmatch =1
EndIf
If bmatch
FullFileName.s = StartDir + #Cdir + FileName
AddElement(LFiles())
Lfiles()\value = FullFileName
Lfiles()\type = #PB_DirectoryEntry_File
FileCount+1
bmatch =0
EndIf
Next
Else
tdir = DirectoryEntryName(mDir)
If tdir <> "." And tdir <> ".."
If Recursive = 1
depth + 1
GetFileList(startDir + #Cdir + tdir,LFiles(),Pattern,Recursive,bset)
EndIf
EndIf
EndIf
Wend
FinishDirectory(mDir)
EndIf
ProcedureReturn FileCount
EndProcedure
Procedure Indexof(*request.Atomic_Server_Request)
Protected *Atomic_Server.Atomic_Server = *request\Serverid
Protected *atomic_client.Atomic_Server_Client = *request\clientID
Protected NewList myfiles.folderContents()
GetFileList("./www/",myfiles())
Protected file.s,content.s = "<!DOCTYPE html>" + #CRLF$
content + "<html><head>" + #CRLF$
content + "<title>" + *Atomic_Server\Title + "</title>" + #CRLF$
content + "</head><body>"
ForEach myfiles()
file.s = RemoveString(myfiles()\value,"./www/")
content + "<a href="+ #DQUOTE$ + file + #DQUOTE$ + ">" + file + "</a></br>"
Next
content + "</body>"
*request\status = 200
*request\ContentType = "text/html"
Protected *Data = UTF8(content)
ProcedureReturn *data
EndProcedure
Global server1 = Atomic_Server_Init("atomic_webserver","./www/","127.0.0.1","",8080,#PB_Network_IPv4,5000)
Atomic_Server_Add_Handler(server1,"indexof",@Indexof())
OpenConsole()
If Atomic_Server_Start(server1,-1,1) ;start server no window logs to console
Repeat
Until Input() = "quit" ;type quit to exit
Atomic_Server_Exit(server1)
CloseConsole()
EndIf
Re: atomic web server threads
Thanks for trying to help with this Idle. Sorry, I don't know a lot about working with TCP/IP or indeed HTML, can you tell me what I need to do with that indexer you made?
Is that indexer necessary to allow other computers to be able to download something from the contents of the www folder?
Is it correct that I should not be able to download a file that I add to your www folder when I run a fresh download of your single_server_localhost?
Is that indexer necessary to allow other computers to be able to download something from the contents of the www folder?
Is it correct that I should not be able to download a file that I add to your www folder when I run a fresh download of your single_server_localhost?
Re: atomic web server threads
I just updated my post above removing the ./www/
if you use a program like wget it will just follow the href links
so if you add any files to the server directory a call to http://indexof will return a simple html page with all the files so wget should fetch them all
to do a subdirectory you can do it like
GetFileList("./www/assets",myfiles())
you can use
wget -r --follow-tags=a http://192.168.1.x
or alternatively you can change the indexof function to output the paths to a txt file
if you use a program like wget it will just follow the href links
so if you add any files to the server directory a call to http://indexof will return a simple html page with all the files so wget should fetch them all
to do a subdirectory you can do it like
GetFileList("./www/assets",myfiles())
you can use
wget -r --follow-tags=a http://192.168.1.x
or alternatively you can change the indexof function to output the paths to a txt file
Re: atomic web server threads
Hi Idle, sorry, I don't really understand what I should be doing. I lack the knowledge that you may be assuming I have.
Do I run your example 'single_server_localhost' before the example you shared, or after, or put them in the same program?
Your new example is working with port 8080, and that won't open, even if I have 80 open already as an instance of your 'single_server_localhost' program.
At the minute, i'm just trying to be able to download a photo that I place in your 'www' folder, from my phone, both regsitered on the same wifi network.
I don't really need to see an index of the files, i'm not sure if the phone does...
I'll be typing '192.168.x.xxx/1.jpg' into my phone and trying to download an image file called '1.jpg' that is located in the 'www' folder of your example.
What do I need to do to achieve that?
P.S. Why is the PB Forum server very slow these days?
Do I run your example 'single_server_localhost' before the example you shared, or after, or put them in the same program?
Your new example is working with port 8080, and that won't open, even if I have 80 open already as an instance of your 'single_server_localhost' program.
At the minute, i'm just trying to be able to download a photo that I place in your 'www' folder, from my phone, both regsitered on the same wifi network.
I don't really need to see an index of the files, i'm not sure if the phone does...
I'll be typing '192.168.x.xxx/1.jpg' into my phone and trying to download an image file called '1.jpg' that is located in the 'www' folder of your example.
What do I need to do to achieve that?
P.S. Why is the PB Forum server very slow these days?


