The browser is the new GUI !



Task

Serve our standard text   Goodbye, World!   to   http://localhost:8080/   so that it can be viewed with a web browser.

The provided solution must start or implement a server that accepts multiple client connections and serves text as requested.

Note that starting a web browser or opening a new window with this URL
is not part of the task.

Additionally, it is permissible to serve the provided page as a plain text file (there is no requirement to serve properly formatted HTML here).

The browser will generally do the right thing with simple text like this.




/* NetRexx */
options replace format comments java crossref symbols binary
 
class RHelloWorldWebServer public
 
  properties public constant
    isTrue = boolean (1 == 1)
    isFalse = boolean (1 \== 1)
    greeting1 = "Goodbye, World!"
    greeting2 = '' -
      || 'HTTP/1.1 200 OK\r\n' -
      || 'Content-Type: text/html; charset=UTF-8\r\n\r\n' -
      || '<?xml version="1.0" encoding="UTF-8"?>\r\n' -
      || '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r\n' -
      || '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\r\n' -
      || '<header>\r\n' -
      || '<title>Hello</title>\r\n' -
      || '<style type="text/css">body {font-family: sans-serif;}</style>\r\n' -
      || '</header>\r\n' -
      || '<body>\r\n' -
      || '<h2 style="text-align: center;">' || greeting1 || '</h2>\r\n' -
      || '</body>\r\n' -
      || '</html>\r\n' -
      || ''
 
  properties static inheritable
    terminate = isFalse -- TODO: provide a less draconian means to terminate the listener loop
 
  method main(args = String[]) public static signals IOException
    listener = ServerSocket(8080)
    loop label listener forever
      if terminate then leave listener
      sock = listener.accept()
      PrintWriter(sock.getOutputStream(), isTrue).println(greeting2)
      sock.close()
      end listener
    return
 