Hello
it's possible to generate HTML code and send to a client (using BBC software as server) ?
Thank
Jo
HTML
Re: HTML
Yes, simple web servers have previously been written in BBC BASIC. Here's one by Jon Ripley from 2007 that I found lying around, it's compatible with both BBC BASIC for Windows and BBC BASIC for SDL 2.0:
Code: Select all
REM Jon Ripley's Simple Web Server
INSTALL @lib$+"socklib"
PROC_initsockets
ON ERROR ON ERROR OFF:PROC_exitsockets:PRINT REPORT$" at line ";ERL:END
ON CLOSE PROC_exitsockets:QUIT
eol$ = CHR$13+CHR$10
host$ = FN_gethostname
port$ = "80"
PRINT "Host name is """host$""""
REPEAT
listen_socket% = FN_tcplisten(host$,port$)
IF listen_socket% <= 0 ERROR 100, "Failed to create socket"
PRINT '"Listening on port ";port$
REPEAT
SYS "Sleep", 1
accept_socket% = FN_check_connection(listen_socket%)
UNTIL accept_socket%
IF FN_readlinesocket(accept_socket%, 6000, line$)
PRINT "Request:"line$
REPEAT
IF FN_readlinesocket(accept_socket%, 6000, head$)
PRINT"Header:";head$
UNTIL head$=""
IF LEFT$(line$,4)="GET " THEN
reply$="HTTP/1.0 200 OK"+eol$+"Content-type: text/html"+eol$+eol$+\
\"<html><head><title>Hello World!</title></head><body>"+\
\"<h1>Hello World!</h1><hr>Powered by <i>BBC BASIC</i>"+\
\"</body></html>"
ELSE
reply$="HTTP/1.0 501 Not Implemented"+eol$+"Content-type: text/plain"+eol$+eol$+\
\"501 - Method not implemented"
ENDIF
IF reply$<>"" IFFN_writelinesocket(accept_socket%,reply$)
PROC_closesocket(accept_socket%)
UNTIL FALSE
Re: HTML
My guess: you have the Lowercase keywords option turned on (LINE is a keyword, being displayed in orange, by default, is the giveaway).
Since BBC BASIC has always required keywords to be in CAPITALS, right back to the original version in 1981, you will commonly encounter programs that are incompatible with this option. You are strongly advised not to use it; if you do, be prepared to make the necessary changes when incorporating code written by other people.
The Cross-reference utility (Utilities menu in both BBC BASIC for Windows and BBC BASIC for SDL 2.0) issues a warning if it finds that the program is incompatible with the Lowercase keywords mode.
Re: HTML
Read again what I wrote above - LINE is a keyword, you cannot use it as a variable name!

The code I listed works correctly, so long as you do not enable the Lowercase keywords option and copy-and-paste it accurately.
In particular, compare the line you listed:
Code: Select all
IF FN_readlinesocket(accept_socket%, 500, LINE$)
Code: Select all
IF FN_readlinesocket(accept_socket%, 6000, line$)