Basic Univers
Enumeration
#Window_0
EndEnumeration
Enumeration
#String_0
#Button_0
#Web_0
EndEnumeration
Procedure Open_Window_0()
If OpenWindow(#Window_0, 253, 11, 443, 412, "Pico Web", #PB_Window_MaximizeGadget | #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_SizeGadget)
If CreateGadgetList(WindowID(#Window_0))
EditorGadget(#String_0, 0, 0, 440, 130)
ButtonGadget(#Button_0, 0, 130, 440, 20, "Transmettre données")
WebGadget(#Web_0, 0, 150, 440, 260, "")
SetGadgetText(#String_0 , "Test envoie direct")
EndIf
EndIf
EndProcedure
If InitNetwork() = 0
MessageRequester("Error", "Can't initialize the network !", 0)
End
EndIf
Port = 8070
*Buffer = AllocateMemory(10000)
Global page$
If CreateNetworkServer(0, Port)
Open_Window_0()
SetGadgetText(#Web_0, "http://127.0.0.1:8070")
Repeat
Repeat
WEvent = WindowEvent()
If WEvent = #PB_Event_SizeWindow
ResizeGadget(#String_0, 0, 0, WindowWidth(#Window_0), WindowHeight(#Window_0)/2)
ResizeGadget(#Web_0, 0,(WindowHeight(#Window_0)/2)+ 20, WindowWidth(#Window_0), WindowHeight(#Window_0)/2)
ResizeGadget(#Button_0, 0,(WindowHeight(#Window_0)/2), WindowWidth(#Window_0), 20)
EndIf
If WEvent = #PB_Event_CloseWindow
Quit = 1
EndIf
If WEvent = #PB_Event_Gadget
If EventGadget()=#Button_0
page$ = GetGadgetText(#String_0)
SetGadgetState(#Web_0, #PB_Web_Refresh)
EndIf
EndIf
Until WEvent = 0
SEvent = NetworkServerEvent()
If SEvent
ClientID.l = EventClient()
Select SEvent
Case 1
Case 4
Default
RequestLength.l = ReceiveNetworkData(ClientID, *Buffer, 2000)
Gosub ProcessRequest
EndSelect
Else
Delay(20)
EndIf
Until Quit = 1
CloseNetworkServer(0)
Else
MessageRequester("Pico Web", "Error: can't create the server (port in use ?).", 0)
EndIf
End
ProcessRequest:
ContentType$ = "text/html"
head$ = "HTTP/1.1 200 OK"+#CRLF$
head$ = head$ +"Date: Wed, 07 Aug 1996 11:15:43 GMT"+#CRLF$
head$ = head$ +"Server: Pico Web Server 0.1"+#CRLF$
head$ = head$ +"Content-Length: " + Str(Len(page$))+#CRLF$
head$ = head$ +"Content-Type: " + ContentType$ +#CRLF$
head$ = head$ +#CRLF$
page$ = head$ + page$
SendNetworkString(ClientID, page$)
Return