TCP/UDP provides a communication channel between the client and the server, which is the layer 4 protocol and performs communication management.
Because the communication channel is a so-called port, different TCP/UDP port even in the same IP address provides the different services.
For example, in the server with an IP of 192.168.1.1, the DNS service(Bind / UDP port 53), HTTP service (Apache / TCP port 80) and the SMTP service (Postfix / TCP port 25) were running.
If the client access to the server with 192.168.1.1 TCP 80 port, HTTP service will be provided.
If the connection is 192.168.1.1 UDP 53 port , provides the DNS service.
And if the connection is 192.168.1.1 TCP 25 port , SMTP services will be provided.
In this case, it does not have much sense what number the client's port number. But for example, you may go the two TCP connections from the same client different TCP port to the HTTP service to be established, on the server side, it is useful two of the communication of the same client to identify.
It should be noted that the port assignment of the IANA has done, IANA of the page has been published to.
Proper use of TCP and UDP
TCP, in particular, high reliability (consult before communication by 3way handshake, acknowledgment and retransmission processing of the opponent by the ack, etc.) and optimize the function of the communication efficiency will provide the flow control and congestion control by the Window. Therefore, it takes a load in comparison with the UDP.
On the other hand, UDP because of the simple structure of only to provide a communication channel and a checksum to the transmission partner, the load is lighter, it does not have the ability to provide the efficiency and reliability of communication. Communication is also one-sided.
TCP is suitable for communication required reliability such as Web communication, e-mail communication, file transfer, and so on.
On the other hand, UDP has been facing and real-time applications such as voice and video, or simple protocols such as syslog or DNS, NTP, SNMP, TFTP. (However, the video site in recent years is the most able to use the TCP.)
In addition, some protocol on UDP is one direction as syslog, some are bi-directional as DNS and NTP.
In TCP, it has defined the exchange of data between the client application ⇔ server applications.
The figure below is an image view of the client's InternetExplorer to the exchange of data in the TCP to the server of the Apache.(Apache is a typical Web server software.)
Such as "192.168.1.1:50001 ⇔ 10.0.0.1:80", the combination of "source IP address: source port, destination IP address:destination port" is called to socket (socket).
Client application (browser) and also server application (Apache) manages the communication in units of the socket. For this reason, even different port number of the same clients , you can also at the same time access the same server port.
Applications span the virtual circuit this socket as an identifier, to establish a TCP connection.In this case, IP routing path, there is no problem though unlike in the go and return.Even the middle of the route is changed in a dynamic routing protocol such as RIP or OSPF, TCP connection will not broken (if restarts the communication until TCP timeout is comming).
This is because, in the NW devices that operate at layer 3 below does not recognize the connection, because that is recognized only between client / server host.
However, since the layer 4 or more of the NW devices such as firewall has the ability to manage the round-trip of TCP connections and UDP, if there is a firewall in the middle of the route you will need to shuttle to go and return by the same route.
As an aside, the socket is also in application development, API that socket API are provided (Windows sockets API is called a particularly Winsock).
Because programmers If communication is needed on the program may only call this socket API, you do not have to write a program related to communication.
It is further an aside, Winsock has been changing progressively depending on the version of the OS.Particularly significant change, in Windows XP SP2 or later, is that prohibited the RAW socket.
Normal socket is generated by the automatic TCP / UDP header at the time of data transmission, but it is output, and use the RAW socket, Ethernet header, including the IP header, all users can be generated manually.Since this has been used only to end up bad, MS has been prohibited for security, because it seems to be the situation.