DEV Community

Cover image for Web Application Programming in PicoLisp: Setting up the server
Mia
Mia

Posted on • Originally published at picolisp-explored.com

Web Application Programming in PicoLisp: Setting up the server

Now that we know how to create a HTTP-response out of a PicoLisp script, let's set up a server and try it out.


What actually is a server?

When speaking of servers, many people think of large, specialized computers that are stored somewhere under the earth and do secret, mysterious stuff.

But in its most basic meaning, a server is just a piece of software that does just this: serving things to other program (the clients). Of course this can also happen within just one computer. In this case, we call it "application server" or "local server", as opposed to the "web server" that can be accessed via the internet.

Processes that are accessible by other processes are running on so-called ports. These ports are "communication endpoints", which means that the client is sending the request to this location. In theory, any port number between 1 and 65535 can be used. In practice, there are standard ports for different applications.

Now let's see it in action.


Setting up the PicoLisp server

What job does our PicoLisp server have? Well, when the browser asks for a specific file, for example "helloworld.l", it needs to ask the PicoLisp interpreter to execute that file before sending it to the client.

But before we do that, we should save our "hello world"-example from the last post to file. Otherwise our server will have nothing to serve. Create a file called helloworld.l with the following content:

(html 0 "Hello" NIL NIL
   (prinl "Hello World!") )
Enter fullscreen mode Exit fullscreen mode

Now let's start the server with this command from the command line:

$ pil @lib/http.l @lib/xhtml.l @lib/form.l  --server 8080 +
Enter fullscreen mode Exit fullscreen mode

What do we do here? First, we load three libraries: @lib/http.l, @lib/xhtml.l and @lib/form.l, as we will need these to successfully render our html-pages. Then we specify the server and port number by --server <port-number>. The + at the end opens the debugging mode, which is helpful to see what is going on.


Now we want to open the file helloworld.l from the browser. So point your browser towards http://localhost:8080/helloworld.l to see the output:

helloworld.png

Why "localhost"? localhost refers to the current computer. Since the PicoLisp server is only running locally, you will not be able to view this page from a system outside your computer.

What happens if we try to open a file that does not exist, for example error.l? In this case, the debugger will throw an error:

$ pil @lib/http.l @lib/xhtml.l @lib/form.l  --server 8080 +
!? (load File)
"error.l" -- Open error: No such file or directory
Enter fullscreen mode Exit fullscreen mode

We can stop the server with Ctrl-C.


Our "Hello World" text looks quite lonely. Let's see how we can wrap it into some HTML tags in the next post.


Sources

Top comments (0)