The term “server” is used a lot these days to refer to a computer – usually one that is being shared by various users and/or not used as a workstation. But a server also refers to a program that runs constantly, usually in the background, waiting for commands. Just about every computer is technically a “server” because the operating system runs several server processes. Unix people like to call them daemons. Windows people like to call them services.
Here’s a simple example. When you browse to a web page, your machine actually contacts the web server and requests a file. The reason this works is because the server computer has a program (in this case an HTTP server) running. your computer connects to the remote machine. they greet each other. your machine issues a command and the other does the requested action. In the case of a web page, the remote machine sends you the html file that you requested.
You can test this out yourself using telnet. Open a DOS window and type the following:
telnet www.yahoo.com 80
you’ve probably used telnet before. you may not have known that if you enter a number after the address, it specifies the remote port. if you omit the number, it defaults to 25, which is the normal telnet port for shell access. we’re connecting on port 80, because that is the port on which the http/web servers normally listen. you’ll see a quick connect message, then the screen will go blank. at this point you are connected to yahoo and it is waiting for a command. Type the following:
get /
Hit enter after the /. You’ll notice that you can’t see the input you’re typing. This is the normal behavior of an http server. If you typed correctly, though, you’ll see a bunch of HTML output scroll by followed by a message that you have been disconnected. You just manually surfed the front page of yahoo.com! If you’ve done a little web programming, you’re probably familiar with the GET request. This is probably the most basic HTTP command. “GET /” simply requests from the server the default root document “/”. If you know the exact file you want, you can get it with something like this: “GET /mypath/myfile.html” You can put in script arguments as well like so: “GET /cgi-bin/script.pl?a=1&b=2″
Behind the scenes, this is exactly what your browser does. It connects to the remote server and sends commands. Of course, the HTTP protocol has a lot more to it and modern browsers do all kinds of things on the client end as well, like render graphics, process scripts, etc.
The same thing also happens when you check email except a POP server listens on (usually) port 110. You can try telneting into your POP server on port 110 and entering some commands. In this case you have to authenticate and there is a special sequence of commands outlined in the POP Protocol specifications.
An interesting thing to note is that computers use this same technique for internal communication as well. Some of the services that make your computer work are always running, listening on a specific port, waiting for commands. You can use telnet in the same way to poke around your computer’s local services. Download this application from Sysinternals called TCPView from [url]http://www.sysinternals.com/ntw2k/source/tcpview.shtml[/url]. When you run this program, it will show you all open ports on your system. Any port that says “LISTENING” is waiting for commands. You can try connecting to it by typing:
telnet localhost [portnum]
(replace [portnum] with whatever port number you want). Many windows services will not accept a connection in this way. Some accept a connection, but are expecting binary data, so you cannot really enter any commands. However, some use plain text and you can have some fun experimenting.
Behind all those layers of nice looking windows and graphics, this is how the true work is often done on your computer. It reminds me a lot of my old computers where everything was command-line based. To use them, you had to learn the basic syntax. Today we have simple user interfaces, but under the hood our input is still converted into commands. Kinda cool.