« back

Building an Echo Server in Clojure - Part 1

12 Nov 2012

A.K.A "Why are Computer?"

Today I was presented the challenge to get started on building an echo server using Clojure....

I am pretty excited about this project because to me, there is still a lot of mystery surrounding this topic. I still have this black box around the computer in general and I am eager to get some time to peek inside.

Doug gave me 3 references as a starting out point with information about sockets. At about 9:30am I started reading the first piece of material and the next time I looked up it was 11:45am and I was about 4 links deep in wikipedia reading about threads and scheduling. My brain ached.(in a good way). Every time I read about a new topic it would result in at least two to three more topics that I would open up new tabs for in wikipedia. Whew! This is a lot of material. Maybe I should be embarrassed that I have been writing small apps without this knowledge. I'm going to choose not to be and instead be excited about things that I am learning that may be so elementary to you that you are rolling your eyes right now right before you close this window. That's cool, but do check back in with this series because I will actually get to building a chat server. (and it will be sweet.)

Here are some of the things today that were completely new to me. A lot of them allowed me to finally say. "Oh, that's why that is like that" or "Oh, that what that means." Others had me thinking "Wait a minute, I can not even finish this one sentence without looking up 3 of these words to know what they are talking about."

What is a server? That would probably be good to know, right? Well, In most common use, according to Wikipedia...

A server is a physical computer (a computer hardware system) dedicated to run one or more services (as a host), to serve the needs of the users of other computers on the network. Depending on the computing service that it offers it could be a database server, file server, mail server, print server, web server, gaming server, or some other kind of server.

In the context of client-server architecture, a server is a computer program running to serve the requests of other programs, the "clients". Thus, the "server" performs some computational task on behalf of "clients". The clients either run on the same computer or connect through the network. In the context of Internet Protocol (IP) networking, a server is a program that operates as a socket listener.

Okay, so what is a client? from Wikipedia...

A client is an application or system that accesses a service made available by a server. The server is often (but not always) on another computer system, in which case the client accesses the service by way of a network. The term was first applied to devices that were not capable of running their own stand-alone programs, but could interact with remote computers via a network. These dumb terminals were clients of the time-sharing mainframe computer.

So What is a network? from Wikipedia...

A computer network, or simply a network, is a collection of computers and other hardware interconnected by communication channels that allow sharing of resources and information. Communications protocols define the rules and data formats for exchanging information in a computer network, and provide the basis for network programming. Computer network programming involves writing computer programs that communicate with each other across a computer network. Different programs must be written for the client process, which initiates the communication, and for the server process, which waits for the communication to be initiated. Both endpoints of the communication flow are implemented as network sockets; hence network programming is basically socket programming.

I also keep seeing TCP, so let's talk about that...from Wikipedia...

The Transmission Control Protocol (TCP) is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol (IP), and therefore the entire suite is commonly referred to as TCP/IP. TCP provides reliable, ordered delivery of a stream of octets from a program on one computer to another program on another computer. TCP is the protocol used by major Internet applications such as the World Wide Web, email, remote administration and file transfer. TCP provides a communication service at an intermediate level between an application program and the Internet Protocol (IP). That is, when an application program desires to send a large chunk of data across the Internet using IP, instead of breaking the data into IP-sized pieces and issuing a series of IP requests, the software can issue a single request to TCP and let TCP handle the IP details. IP works by exchanging pieces of information called packets. A packet is a sequence of octets and consists of a header followed by a body. The header describes the packet's destination and, optionally, the routers to use for forwarding until it arrives at its destination. The body contains the data IP is transmitting. TCP is optimized for accurate delivery rather than timely delivery, and therefore, TCP sometimes incurs relatively long delays (in the order of seconds) while waiting for out-of-order messages or retransmissions of lost messages.

Ah, so we are back to socket programming. I have omitted many other research tangents such as users, threads, scheduling, subnets, netmasks, and network packets.(there were even more but I will stop) Reading about these topics was good to help me feel more comfortable proceeding in my main mission and I would like to revisit them each individually. from Wikipedia...

A network socket is an endpoint of an inter-process communication flow across a computer network. Today, most communication between computers is based on the Internet Protocol; therefore most network sockets are Internet sockets. A socket API is an application programming interface (API), usually provided by the operating system, that allows application programs to control and use network sockets. Internet socket APIs are usually based on the Berkeley sockets standard. A socket address is the combination of an IP address and a port number, much like one end of a telephone connection is the combination of a phone number and a particular extension. Based on this address, internet sockets deliver incoming data packets to the appropriate application process or thread. There are several types of sockets. Computer processes that provide application services are called servers, and create sockets on start up that are in listening state. These sockets are waiting for initiatives from client programs.

I'll stop here just in case you were going into a wikipedia coma. Here are two things that were reinforced to me.
1. I love wikipedia. I am thankful that instead of running out of information, I reach a point where I have to actually cut myself off. Every time this happens I love wikipedia a little bit more.
2. I really need to explore more of this side of things. I can see how having this type of knowledge will help me to have a more refined ability to make decisions about use, end goals, and the process options we could use when creating applications.

Stay tuned!

comments powered by Disqus