The terminal

We won't be building a full-blown web HTTP client application. Instead, we will use an existing app capable of communicating with servers via the Internet. This application can establish a connection (i.e. create a portal) and send some text back and forth. It doesn't know anything about HTTP.

Our goal is to use this app and manually do things that web clients do automatically.

This existing app is called netcat (often abbreviated to nc), and it is not graphical: it doesn't have an icon to double click and it won't show any nice windows and buttons when you start it. In order to run and interact with nc, you have to work with a Terminal.

You've probably seen this already: a (usually) black screen with white text, and lots of lines of seemingly undecipherable stuff. This is how hackers are portrayed in movies. This is where many developers spend their days. We will talk in detail about terminals, command line utilities and Bash shell in future courses and books, but for now – here is a short intro, just enough to get you up to speed.

First computers didn't have graphics. Well, first first computers didn't even have screens, but those that had screens didn't have any on-screen graphics like buttons, images, text fields or menus. They looked like glorified typewriters that "talk back": you type something, hit "Enter" and it types something in response.

Modern computers are billions of times faster and more capable, but this sort of typewriter-like textual interaction is still in the core of programming and system administration. Like it or not, you will have to learn to deal with it.

Imagine you have an app that shows the contents of documents. How would it look like? Maybe, it's just a small window with some sort of a file selector and a button that says "Show". Select a file, hit the button and the contents of the file is displayed on the screen.

It is possible to accomplish the same feature without windows and buttons.

First, you need to somehow launch the app, without having any icons or menu items. This app has a name – fileviewer. This is how you run an app via textual terminal: by typing its name:

fileviewer

Okay, assuming this works, there are different ways to proceed. First way is hit "Enter", which will just launch the app. It might greet us and tell us what to do next, something like this:

Welcome to fileviewer!
Please, enter the path to a file:

Or maybe this fileviewer app works differently (its developer decided so), and says:

Error! No file specified.

Which means it probably expected us to type the address of a file on the same line with the app name, like so:

fileviewer /Users/sam/Desktop/file.txt

The way a text-based app works is defined by its creator, the developer. There are no strict rules, but there are certain conventions and expectations. Many command line apps work like the latter example: they expect some "parameters" to be specified after the their name, on the same line.

The nc app works like this: it expects you to enter some information right after its name and then hit Enter.

Getting nc

  • If you're on Windows, please follow our guide on setting up a good programming environment. Then, use chocolatey to install nc by typing chocolatey install netcat
  • If you're on macOS, you already have nc installed, since it comes built in.