Thursday, 8 November 2012

TCP vs UDP


When an application communicates across the network it has to make a choice between TCP and UDP. It is actually choice between reliable and unreliable communication.

TCP: is reliable, it builds the connection with the device it is communicating with.

UDP: connectionless world, device do not introduce itself to the device it is sending the data to, I just say here is the data and send it to the destination address, destination may not be ready for that packet and can drop it. It is just best effort delivery, it send the packet and hope that it will reach the destination. It makes UDP an unreliable protocol. But this is great for real-time traffic such as VoIP that need speed, when I am speaking on the phone there is no need to resend the dropped data as the conversation is progressing, in case of online games if any movement is dropped there is no reason to backup or resend that as the game is progressing.

TCP: use sequence number, means all the packets that it sends are tagged with a number, for example this is the 5th packet, this is the 6th packet. With this number the packets which are received at the destination out of order can be rearranged with the original or proper order. Everything send via TCP is acknowledged.
TCP uses Three-Way-Handshake. TCP communication is like a phone call.

TCP is  
1)      Reliable.
2)      Session based.
3)      Uses sequence numbers.


After the three-way handshake is completed the computer start sending or receiving data from the server it is communicating with.


 

TCP Windowing

Increase how much data it send based on how reliable the connection is.




Every time an application communicates across the network it’s not only going to chose UDP, TCP but also selects the source and destination Port numbers.
HTTP uses TCP port 80,,,,,,,,,,,, the source/destination address along with TCP/UDP port number is called SOCKET address.
Now, what if you wanted to run an FTP server, which is a server that allows you to transfer and receive files from remote computers, on the same web server. FTP servers use TCP ports 20 and 21 to send and receive information, so you won't have any conflicts with the web server running on TCP port 80. Therefore, the FTP server application when it starts will bind itself to TCP ports 20 and 21, and wait for connections in order to send and receive data.
People that govern IP addresses and maintain well-known port numbers are IANA. Port number tells the receiver that what application the sender is trying to access.
There are total of 65,535 TCP Ports and another 65,535 UDP ports. A port number 900 on TCP may or may not be same as port 900 on UDP.

 
If you have made any online game then you cannot use 0 to 1023 port numbers as they are reserved for other well known services that you cannot touch. So you have to choose one of the other (1024-49151) or (49152-65535) port numbers.
POP3 is post office protocol that is used when we receive email by opening outlook email client and download it from a server.
HTTPS secure web surfing. 443 port TCP.
TCP applications are far more common than UDP. As most people want reliable communication for their services.




No comments:

Post a Comment