Browse Gopher with nothing but Unix
In the article a Gopher server in 9 lines of Python I was on the server side, building a simple implementation. It is a fun and interesting exercise, because the specification is not very long. You learn the basics, and you end up with your own piece of Gopher technology.
Now we are going to do the same, but without code. We will browse Gopherspace using only Unix commands. Specifically, nc (netcat) to open a TCP connection and printf to define what we send.
We will play with gopher://gopher.floodgap.com, one of the oldest servers around.
Open the connection
First we need a command that can connect to a TCP port and send data. Gopher uses port 70 by default.
nc gopher.floodgap.com 70
When you run it you will see nothing. It returns an empty line, and that is exactly what we expect! The connection is open, but the server is waiting for us to tell it what we want.
Request the main menu
The server will reply with its main menu if we send a carriage return and a line feed (\r\n). In our case, pressing "Enter" is enough.
Or, better, chain a printf with a pipe to control exactly which characters we send.
printf '\r\n' | nc gopher.floodgap.com 70
It will print the whole menu. Something like this (trimmed):
iWelcome to Floodgap Systems' official gopher server. error.host 1
iFloodgap has served the gopher community since 1999 error.host 1
...
1Getting started with gopher, software, more /gopher gopher.floodgap.com 70
...
.
Each line starts with a character that tells you the resource type: 1 is another menu, 0 is a text file, i is informational text.
What you see in the terminal is not exactly what the server sends. There are invisible characters. To see them, add cat -vt at the end of the pipe.
printf '\r\n' | nc gopher.floodgap.com 70 | cat -vt
iWelcome to Floodgap Systems' official gopher server.^I^Ierror.host^I1^M
iFloodgap has served the gopher community since 1999^I^Ierror.host^I1^M
...
1Getting started with gopher, software, more^I/gopher^Igopher.floodgap.com^I70^M
...
.^M
^I is a tab and ^M is the carriage return. Fields are separated by tabs and every line ends in \r\n. That lonely dot at the end is the server's way of saying "I'm done".
Pick a jump
Our goal is to reach the explanation of Gopherspace by jumping from menu to menu, or in other words, by making requests.
Let's find the jump we are interested in.
To keep the line short, I have put a line break where there is actually a tab.
1Getting started with gopher, software, more
/gopher
gopher.floodgap.com
70
Every menu line always has the same structure:
[type][text] TAB [selector] TAB [domain] TAB [port]
The selector is the path we must send to the server to request that resource.
With the selector we can prepare the next request.
printf '/gopher\r\n' | nc gopher.floodgap.com 70
We find another menu, with the same format as the previous one:
1Floodgap Systems gopher root / gopher.floodgap.com 70
iWelcome to Gopherspace! error.host 1
...
0A Brief Introduction to Gopherspace -- READ ME FIRST! /gopher/welcome gopher.floodgap.com 70
...
.
I go straight to READ ME FIRST!.
0A Brief Introduction to Gopherspace -- READ ME FIRST!
/gopher/welcome
gopher.floodgap.com
70
This time it starts with 0: it is a text file, not a menu.
Read a document
We prepare the last request to reach our destination.
printf '/gopher/welcome\r\n' | nc gopher.floodgap.com 70
And the server returns the text, the same one you would see with a Gopher client.
Floodgap HELP: What is Gopher?
updated 27 December 2000
gopher n. 1. Any of various short tailed, burrowing mammals of
the family Geomyidae, of North America. 2. (Amer. colloq.)
Native or inhabitant of Minnesota: the Gopher State.
3. (Amer. colloq.) One who runs errands, does odd-jobs, fetches
or delivers documents for office staff. 4. (computer tech.)
Software following a simple protocol for tunneling through a TCP/IP
internet.
Welcome to Gopherspace!
After 3 requests, we have reached our destination! All by following the links in the menus.
Search engine
Gopher also has search engines, both in the specification and as an indexing service (similar to Google). The best known is Veronica-2, and Floodgap links to it from its main menu with the selector /v2.
printf '/v2\r\n' | nc gopher.floodgap.com 70
Inside we find a line of a new type, the 7:
7Search Veronica-2
/v2/vs
gopher.floodgap.com
70
A 7 is a search. It is the only case where the client sends something more than a path: the selector, a tab and the search terms.
printf '/v2/vs\temacs\r\n' | nc gopher.floodgap.com 70
iVeronica-2 2.058.2 (C)2000-2022 Cameron Kaiser
i** Search in progress, please wait **
i*** Search terms: emacs ***
iFirst 30 selectors displayed (page 1).
...
The response is a plain, ordinary menu, with the same lines as always. You can keep jumping from any of the results.
A one-line shortcut
Look closely: all the requests are the same. Only the domain and the selector change. Why not turn it into a shell function?
gopher() { printf '%s\r\n' "$2" | nc "$1" 70; }
Paste it into your terminal (Bash or Zsh) and you can start browsing.
gopher gopher.floodgap.com /gopher/welcome
To search, pass the tab inside the selector:
gopher gopher.floodgap.com "$(printf '/v2/vs\temacs')"
You could even create another shortcut just for Gopher searches, or write a small Python script to make the flow more interactive.
Final notes
How simple it is, and how well it fits with Unix commands, makes it a pleasure to work with.
I hope this article has planted in you a little passion for Gopher. I leave it up to you which of the endless possibilities you want to spend your creativity on. And if sitting in front of the editor writing code is not your thing, you can always admire its specification while you browse.
- Open the connection
- Request the main menu
- Pick a jump
- Read a document
- Search engine
- A one-line shortcut
- Final notes
This work is under a Attribution-NonCommercial-NoDerivatives 4.0 International license.
Help me keep writing
Every coffee gives me a push toward the next article.
Sure, it's on me!
Comments
There are no comments yet.