Advance Java

Learn New things from Rixosys

HTTP and Other TCP Servers

HTTP and Other TCP Servers

TCP is a transfer protocol. HTTP is built on top of TCP, meaning that every HTTP request uses TCP as its transfer protocol. Other application protocols can use TCP as their transport protocol as well. See the OSI model for more on the theory of network protocols. The basic idea is that TCP (a transfer protocol) is lower-level than HTTP (an application protocol which happens to use TCP).

Every HTTP server you create is necessarily also a TCP server (in the sense that it is a server using TCP as its transfer protocol).

The Node net module exposes some low-level TCP socket operations (such as creating a socket, reading/writing, etc) and allows you to create a TCP server. You could use these functions to then create an HTTP server (since HTTP uses TCP) but you could also use them to build any other kind of protocol that uses TCP.

But, it is in most cases much better to use a higher-level node package like Express that abstracts all the TCP details away from you if all you need is an HTTP server.

In Short: TCP is a transport-layer protocol, and HTTP is an application-layer protocol that runs over TCP.

Detail:To understand the difference (and a lot of other networking topics), you need to understand the idea of a layered networking model. Essentially, there are different protocols that let a computer talk at different distances and different layers of abstraction.

At the very bottom of the network stack is the physical layer. This is where electrical signals or light pulses or radio waves actually transmit information from place to place. The physical layer doesn't really have protocols, but instead has standards for voltages, frequencies, and other physical properties. You can transmit information directly this way, but you need a lot of power or a dedicated line, and without higher layers you won't be able to share bandwidth.

The next layer up is the link layer. This layer covers communication with devices that share a physical communications medium. Here, protocols like Ethernet, 802.11a/b/g/n, and Token Ring specify how to handle multiple concurrent accesses to the physical medium and how to direct traffic to one device instead of another. In a typical home network, this is how your computer talks to your home "router."

The third layer is the network layer. In the majority of cases, this is dominated by Internet Protocol (IP). This is where the magic of the Internet happens, and you get to talk to a computer halfway around the world, without needing to know where it is. Routers handle directing your traffic from your local network to the network where the other computer lives, where its own link layer handles getting the packets to the right computer.

Now we are getting somewhere. We can talk to a computer somewhere around the world, but that computer is running lots of different programs. How should it know which one to deliver your message to? The transport layer takes care of this, usually with port numbers. The two most popular transport layer protocols are TCP and UDP. TCP does a lot of interesting things to smooth over the rough spots of network-layer packet-switched communication like reordering packets, retransmitting lost packets, etc. UDP is more unreliable, but has less overhead.

So we've connected your browser to the web server software on the other end, but how does the server know what page you want? How can you post a question or an answer? These are things that application-layer protocols handle. For web traffic, this is the HyperText Transfer Protocol (HTTP). There are thousands of application-layer protocols: SMTP, IMAP, and POP3 for email; XMPP, IRC, ICQ for chat; Telnet, SSH, RDP for remote administration; etc.

These are the five layers of the TCP/IP networking model, but they are really only conceptual. The OSI model has 7 layers. In reality, some protocols shim between various layers, or can work at multiple layers at once. TLS/SSL for instance provides encryption and session information between the network and transport layers. Above the application layer, Application Programming Interfaces (APIs) govern communication with web applications like Quora, Twitter, and Facebook.

Application Layer -- e.g. HTTP
Transport Layer -- e.g. TCP
Internet Layer -- e.g. IP
Link Layer -- e.g. IEEE 802.2


  • TCP/IP protocols

    TCP/IP is a family of communication protocols used to connect computer systems in a network. It is named after two of the protocols in the family: Transmission Control Protocol (TCP) and Internet Protocol (IP). Hypertext Transfer Protocol (HTTP) is a member of the TCP/IP family.

  • IP addresses

    Each server or client on a TCP/IP internet is identified by a numeric IP (Internet Protocol) address. The two types of IP address are the IPv4 (IP version 4) address and the IPv6 (IP version 6) address.

  • Host names

    A host, or website, on the Internet is identified by a host name, such as Host names are sometimes called domain names. Host names are mapped to IP addresses, but a host name and an IP address do not have a one-to-one relationship.

  • Virtual hosting

    HTTP includes the concept of virtual hosting, where a single HTTP server can represent multiple hosts at the same IP address. You can use virtual hosting in web support by setting up URIMAP resources.

  • Port numbers

    In a server, more than one user process can use TCP at the same time. To identify the data associated with each process, port numbers are used. Port numbers are 16-bit, and numbers up to 65535 are possible, although in practice only a small subset of these numbers is commonly used.

  • IANA media types and character sets

    The Internet Assigned Numbers Authority (IANA) is the international body responsible for assigning names for protocols used on the Internet. Use these links to find out more about the names.

  • The components of a URL

    A URL (Uniform Resource Locator) is a specific type of URI (Universal Resource Identifier). A URL normally locates an existing resource on the Internet. A URL is used when a web client makes a request to a server for a resource.

  • The HTTP protocol

    The correct format for HTTP requests and responses depends on the version of the HTTP protocol (or HTTP specification) that is used by the client and by the server.

  • Status codes and reason phrases

    In the HTTP response that is sent to a client, the status code, which is a three-digit number, is accompanied by a reason phrase (also known as status text) that summarizes the meaning of the code. Along with the HTTP version of the response, these items are placed in the first line of the response, which is therefore known as the status line.

  • Reserved and excluded characters

    To assist with the correct transmission and interpretation of an HTTP request, the use of certain characters in a URL is restricted. These characters must be converted to a safe format when the request is transmitted.

  • HTML forms

    In HTML, forms are areas delimited by a <form> tag, containing text input boxes, buttons, check boxes, and other features of a graphical user interface. Forms are used by web applications to allow users to provide data to be sent to the server.

  • Chunked transfer-coding

    Chunked transfer-coding, also known as chunking, involves transferring the body of a message as a series of chunks, each with its own chunk size header. The end of the message is indicated by a chunk with zero length and an empty line.

  • Pipelining

    Pipelining involves a client sending multiple HTTP requests to a server without waiting for a response. Responses must then be returned from the server in the same sequence that the requests were received.

  • Persistent connections

    Persistent connections between a web client and a server can be reused for more than one exchange of a request and a response.

  • HTTP basic authentication

    HTTP basic authentication is a simple challenge and response mechanism with which a server can request authentication information (a user ID and password) from a client. The client passes the authentication information to the server in an Authorization header. The authentication information is in base-64 encoding.