32 lines
1,000 B
Text
32 lines
1,000 B
Text
// Hello world! mode Server: desde el navegador, escriba localhost:8080
|
|
|
|
#include <hbasic.h>
|
|
Begin
|
|
Declare as Numeric (fd,fdc)
|
|
as Alpha (message,HEAD,head,body,form,html)
|
|
|
|
Let ( HEAD := Cat$("HTTP/1.1 200 OK\n","Content-Type: text/html; charset=UTF-8\n\n") + ("<!DOCTYPE html>\n") )
|
|
|
|
ParsNormal$("title","","Bye-bye baby bye-bye")(head)
|
|
ParsNormal$("style","","body { background-color: #111 } h1 { font-size:4cm; text-align: center; color: black; text-shadow: 0 0 2mm red}")(head)
|
|
ParsNormal$("head","",head)(html)
|
|
ParsNormal$("h1","","Goodbye, world!")(body)
|
|
ParsNormal$("body","",body)(html)
|
|
|
|
ParsNormal$("html","",html)(form)
|
|
Let( form := Cat$(HEAD,form))
|
|
|
|
Let( message := Tran$(">\n<","><", form) )
|
|
Print( message, Newl)
|
|
|
|
/* Open socket in localhost (by default) */
|
|
Let( fd := OpenServerTCP(3,8080) )
|
|
|
|
/* accept conection & send message */
|
|
Let( fdc := Accept(fd) )
|
|
Send(message,fdc)
|
|
|
|
/* close all */
|
|
CloseSocket(fdc)
|
|
CloseSocket(fd)
|
|
End
|