Thanks for this fast reply ! The command is working now, but another error appeared ...
When the callback function is called, It crashes at the end of the procedure.
I'm trying to see if I can use libsagui (
https://github.com/risoflora/libsagui/releases) to implement an embedded webserver.
This code works until you try to visit the url
http://localhost:8080/
Code: Select all
PrototypeC.i Protosg_httpsrv_new(*cb, *cls)
PrototypeC.l Protosg_httpres_sendbinary(*res, *buf, size.l, *content_type, status.l)
PrototypeC.b Protosg_httpsrv_listen(*srv, port, tread.b)
PrototypeC.i Protosg_httpreq_method(*req)
Global sg_httpres_send.Protosg_httpres_sendbinary
Global sg_httpreq_method.Protosg_httpreq_method
hHandle = OpenLibrary(#PB_Any, "libsagui-1.dll")
If hHandle
; ExamineLibraryFunctions(hHandle)
; While NextLibraryFunction()
; Debug LibraryFunctionName()
; Wend
sg_httpsrv_new.Protosg_httpsrv_new = GetFunction(hHandle, "sg_httpsrv_new")
sg_httpres_send.Protosg_httpres_sendbinary = GetFunction(hHandle, "sg_httpres_sendbinary")
sg_httpsrv_listen.Protosg_httpsrv_listen = GetFunction(hHandle, "sg_httpsrv_listen")
sg_httpreq_method.Protosg_httpreq_method = GetFunction(hHandle, "sg_httpreq_method")
EndIf
Procedure req_cb(*cls, *req, *res)
a$ = "<html><head><title>Hello world</title></head><body>Hello world</body></html>"
lena = Len(a$)
b$ = "text/html; charset=utf-8"
Debug PeekS(sg_httpreq_method(*req), -1, #PB_UTF8)
;Return 0 = ok else error
Debug sg_httpres_send(*res, @a$, 0, @b$, 200)
EndProcedure
*srv = sg_httpsrv_new(@req_cb(), #Null)
If sg_httpsrv_listen(*srv, 8080, #False) = #False
Debug "ERROR"
EndIf
OpenConsole()
PrintN("Server is running")
PrintN("this will crash ... http://localhost:8080/")
Input()
CloseLibrary(hHandle)