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.




 
//compile with dylan.NET 11.5.1.2 or later!!
#refstdasm "mscorlib.dll"
#refstdasm "System.dll"
 
import System.Text
import System.Net.Sockets
import System.Net
 
assembly helloweb exe
ver 1.1.0.0
 
namespace WebServer
 
    class public GoodByeWorld
 
        method public static void main(var args as string[])
 
            var msg as string = c"<html>\n<body>\nGoodbye, world!\n</body>\n</html>\n"        
            var port as integer = 8080
            var serverRunning as boolean = true
 
            var tcpListener as TcpListener = new TcpListener(IPAddress::Any, port)
            tcpListener::Start()
 
            do while serverRunning
                var socketConnection as Socket = tcpListener::AcceptSocket()
                var bMsg as byte[] = Encoding::get_ASCII()::GetBytes(msg::ToCharArray(), 0, msg::get_Length())
                socketConnection::Send(bMsg)
                socketConnection::Disconnect(true)
            end do
 
        end method
 
    end class
 
end namespace
 