Skip to contentমূল লেখায় যান

Topic 04 · Courseটপিক 04 · Course

TCP and UDP

Two ways to send a message to a friend: a registered letter and a postcard. For the registered letter, the post office checks that it arrives, in the right order, and tells you if it got lost. The postcard is cheap and quick, but nobody promises anything. TCP is the registered letter. UDP is the postcard.

6 min read6 মিনিটে পড়া যায় · 8 sections8টি সেকশন · 2 sources2টি সোর্স · updated Oct 2026আপডেট: Oct 2026

TCP and UDPTCP আর UDP

Watch TCP shake hands and send lost data again, while UDP just sends. Then change the packet loss.দেখুন TCP হ্যান্ডশেক করে আর হারানো ডেটা আবার পাঠায়, আর UDP শুধু পাঠায়। তারপর packet loss বদলান।

2 min2 মিনিট7 steps7টি ধাপ
  • Packets sentপাঠানো packet10
you · clientআপনি · ক্লায়েন্ট10 packets10টি packetTCPTCPreliableনির্ভরযোগ্যUDPUDPno promiseগ্যারান্টি নেই

You’ll learnআপনি শিখবেন

  • How TCP and UDP differTCP আর UDP-এর তফাত✓
  • What the three-way handshake doesথ্রি-ওয়ে হ্যান্ডশেক কী করে
  • How TCP repairs a lost packetTCP কীভাবে হারানো packet ঠিক করে
  • Why UDP leaves a gapUDP কেন ফাঁক রাখে

In plain words

IP moves packets from one computer to another. TCP and UDP sit on top of IP. They get the data to the right program on that computer, and they differ in how much they promise.

TCP gives a reliable, in-order byte stream to applications Source 1সোর্স 1. It detects lost packets with sequence numbers and damaged data with checksums, and it repairs a loss by sending the data again Source 1সোর্স 1. Each TCP segment travels inside an IP datagram Source 1সোর্স 1.

UDP gives a way to send messages with a minimum of protocol mechanism Source 2সোর্স 2. Delivery and duplicate protection are not guaranteed Source 2সোর্স 2. If an application needs ordered, reliable delivery of a stream, the UDP standard says to use TCP Source 2সোর্স 2.

Both protocols use port numbers to pick the program. In TCP the source port and the destination port are each 16 bits Source 1সোর্স 1. A UDP header has a source port, a destination port, a length, and a checksum Source 2সোর্স 2.

সহজ English

IP moves packets from one computer to another. TCP and UDP sit on top of IP. They get the data to the right program on that computer. They differ in how much they promise.

TCP gives a reliable, in-order byte stream to applications Source 1সোর্স 1. It detects lost packets with sequence numbers. It detects damaged data with checksums. It repairs a loss by sending the data again Source 1সোর্স 1. Each TCP segment travels inside an IP datagram Source 1সোর্স 1.

UDP gives a way to send messages with a minimum of protocol mechanism Source 2সোর্স 2. Delivery and duplicate protection are not guaranteed Source 2সোর্স 2. If an application needs ordered, reliable delivery of a stream, the UDP standard says to use TCP Source 2সোর্স 2.

Both protocols use port numbers to pick the program. In TCP the source port and the destination port are each 16 bits Source 1সোর্স 1. A UDP header has a source port, a destination port, a length, and a checksum Source 2সোর্স 2.

বাংলা ব্যাখ্যা

IP এক কম্পিউটার থেকে আরেক কম্পিউটারে প্যাকেট (packet) নিয়ে যায়। TCP এবং UDP চলে IP-র উপরে। তারা ডেটাকে সেই কম্পিউটারের সঠিক প্রোগ্রামে পৌঁছে দেয়। দুটির পার্থক্য হলো তারা কতটা প্রতিশ্রুতি দেয়।

TCP অ্যাপ্লিকেশনকে একটি নির্ভরযোগ্য, ক্রমানুসারে চলা বাইট স্ট্রিম (byte stream) দেয় Source 1সোর্স 1। সে সিকোয়েন্স নম্বর (sequence number) দিয়ে হারানো প্যাকেট ধরে। চেকসাম (checksum) দিয়ে ক্ষতিগ্রস্ত ডেটা ধরে। ডেটা আবার পাঠিয়ে হারানো অংশ ঠিক করে Source 1সোর্স 1। প্রতিটি TCP সেগমেন্ট (segment) একটি IP ডেটাগ্রামের (datagram) ভেতরে চলে Source 1সোর্স 1।

UDP সবচেয়ে কম প্রোটোকল ব্যবস্থা (protocol mechanism) দিয়ে মেসেজ পাঠানোর একটি উপায় দেয় Source 2সোর্স 2। ডেলিভারি এবং ডুপ্লিকেট থেকে সুরক্ষার নিশ্চয়তা নেই Source 2সোর্স 2। কোনো অ্যাপ্লিকেশনের স্ট্রিম ক্রমানুসারে ও নির্ভরযোগ্যভাবে পৌঁছানো দরকার হলে UDP স্ট্যান্ডার্ড বলে TCP ব্যবহার করতে Source 2সোর্স 2।

দুটি প্রোটোকলই প্রোগ্রাম বেছে নিতে পোর্ট নম্বর (port number) ব্যবহার করে। TCP-তে সোর্স পোর্ট এবং ডেস্টিনেশন পোর্ট প্রতিটি 16 বিট Source 1সোর্স 1। UDP হেডারে থাকে সোর্স পোর্ট, ডেস্টিনেশন পোর্ট, লেংথ (length) এবং চেকসাম Source 2সোর্স 2।

How it works

TCP first builds a connection. This is the three-way handshake:

Client                      Server
  | ---- SYN (my number X) --->  |
  | <--- SYN+ACK (Y, got X) ---  |
  | ---- ACK (got Y) -------->   |
  |   connection is open         |

Each side picks a starting sequence number, and the other side confirms it. Four steps become three messages, because the middle two combine in one message Source 1সোর্স 1. The main reason for the handshake is to stop old duplicate connection requests from causing confusion Source 1সোর্স 1.

While data flows, the receiver tells the sender a window: the range of sequence numbers it can accept now. This is related to its free buffer space Source 1সোর্স 1. A TCP endpoint must also slow down when the network is crowded: it starts slowly, grows its speed with care, and waits longer after each repeated timeout. The goal is to avoid a congestion collapse Source 1সোর্স 1. The timeout is not fixed. It is computed while the connection runs Source 1সোর্স 1.

To close, one side sends a FIN segment. The other side acknowledges it, but it sends its own FIN only when its own user has closed the connection too Source 1সোর্স 1. The side that closes waits for a while in the TIME-WAIT state. This makes sure the peer got the acknowledgment, and it keeps delayed segments of the old connection away from a new one Source 1সোর্স 1. A reset (RST) is the hard stop: it aborts a connection that is open and informs the user Source 1সোর্স 1.

UDP has none of this. There is no handshake and no window. A sender just sends a datagram. The header has a length field, and the minimum length is 8 octets (the header alone) Source 2সোর্স 2. The source port is optional; if it is not used, it is zero Source 2সোর্স 2. An all-zero checksum means that the sender did not compute one Source 2সোর্স 2.

সহজ English

TCP first builds a connection. This is the three-way handshake:

  1. The client sends SYN with its starting number X.
  2. The server answers SYN+ACK. It gives its own number Y and confirms that it got X.
  3. The client sends ACK to confirm that it got Y. Now the connection is open.

Each side picks a starting sequence number, and the other side confirms it. Four steps become three messages, because the middle two combine in one message Source 1সোর্স 1. The main reason for the handshake is to stop old duplicate connection requests from causing confusion Source 1সোর্স 1.

While data flows, the receiver tells the sender a window. The window is the range of sequence numbers that the receiver can accept now. This is related to its free buffer space Source 1সোর্স 1. A TCP endpoint must also slow down when the network is crowded. It starts slowly. It grows its speed with care. It waits longer after each repeated timeout. The goal is to avoid a congestion collapse Source 1সোর্স 1. The timeout is not fixed. It is computed while the connection runs Source 1সোর্স 1.

To close, one side sends a FIN segment. The other side acknowledges it. But it sends its own FIN only when its own user has closed the connection too Source 1সোর্স 1. The side that closes waits for a while in the TIME-WAIT state. This makes sure the peer got the acknowledgment. It also keeps delayed segments of the old connection away from a new one Source 1সোর্স 1. A reset (RST) is the hard stop. It aborts a connection that is open and informs the user Source 1সোর্স 1.

UDP has none of this. There is no handshake and no window. A sender just sends a datagram. The header has a length field. The minimum length is 8 octets (the header alone) Source 2সোর্স 2. The source port is optional. If it is not used, it is zero Source 2সোর্স 2. An all-zero checksum means that the sender did not compute one Source 2সোর্স 2.

বাংলা ব্যাখ্যা

TCP প্রথমে একটি কানেকশন তৈরি করে। একে বলে থ্রি-ওয়ে হ্যান্ডশেক (three-way handshake):

  1. ক্লায়েন্ট তার শুরুর সংখ্যা X দিয়ে SYN পাঠায়।
  2. সার্ভার SYN+ACK দিয়ে উত্তর দেয়। সে নিজের সংখ্যা Y জানায় এবং নিশ্চিত করে যে X পেয়েছে।
  3. ক্লায়েন্ট ACK পাঠিয়ে নিশ্চিত করে যে Y পেয়েছে। এখন কানেকশন খোলা।

প্রতিটি পক্ষ একটি শুরুর সিকোয়েন্স নম্বর বেছে নেয়, আর অন্য পক্ষ সেটি নিশ্চিত করে। চার ধাপ তিনটি মেসেজ হয়ে যায়, কারণ মাঝের দুটি এক মেসেজে মিলে যায় Source 1সোর্স 1। হ্যান্ডশেকের মূল কারণ হলো পুরোনো ডুপ্লিকেট কানেকশন রিকুয়েস্ট যেন বিভ্রান্তি না ঘটায় Source 1সোর্স 1।

ডেটা চলার সময় রিসিভার সেন্ডারকে একটি উইন্ডো (window) জানায়। উইন্ডো হলো রিসিভার এখন যে সিকোয়েন্স নম্বরের পরিসর নিতে পারে। এটি তার ফাঁকা বাফার স্পেসের (buffer space) সঙ্গে সম্পর্কিত Source 1সোর্স 1। নেটওয়ার্কে ভিড় হলে TCP এন্ডপয়েন্টকে ধীর হতে হয়। সে ধীরে শুরু করে। সাবধানে গতি বাড়ায়। প্রতিটি পুনরাবৃত্ত টাইমআউটের পর বেশি সময় অপেক্ষা করে। লক্ষ্য হলো কনজেশন কোলাপ্স (congestion collapse) এড়ানো Source 1সোর্স 1। টাইমআউট স্থির নয়। কানেকশন চলার সময় এটি হিসাব করা হয় Source 1সোর্স 1।

বন্ধ করতে এক পক্ষ একটি FIN সেগমেন্ট পাঠায়। অন্য পক্ষ তা স্বীকার (acknowledge) করে। কিন্তু নিজের FIN পাঠায় তখনই, যখন তার নিজের ইউজারও কানেকশন বন্ধ করেছে Source 1সোর্স 1। যে পক্ষ বন্ধ করে, সে কিছুক্ষণ TIME-WAIT অবস্থায় অপেক্ষা করে। এতে নিশ্চিত হয় যে অপর পক্ষ অ্যাকনলেজমেন্ট (acknowledgment) পেয়েছে। এটি পুরোনো কানেকশনের দেরিতে আসা সেগমেন্টকে নতুন কানেকশন থেকে দূরে রাখে Source 1সোর্স 1। রিসেট (reset, RST) হলো জোর করে থামিয়ে দেওয়া। এটি খোলা কানেকশন বাতিল করে এবং ইউজারকে জানায় Source 1সোর্স 1।

UDP-তে এসবের কিছুই নেই। কোনো হ্যান্ডশেক নেই, কোনো উইন্ডো নেই। সেন্ডার শুধু একটি ডেটাগ্রাম পাঠায়। হেডারে একটি লেংথ ফিল্ড আছে। সর্বনিম্ন লেংথ 8 অক্টেট (octet) (শুধু হেডার) Source 2সোর্স 2। সোর্স পোর্ট ঐচ্ছিক। ব্যবহার না হলে এটি শূন্য Source 2সোর্স 2। সব-শূন্য চেকসাম মানে সেন্ডার চেকসাম হিসাব করেনি Source 2সোর্স 2।

When you need it

Pick TCP when every byte must arrive, in order: a web page, a file, a database call, a login. Pick UDP when speed matters more than perfect delivery, and the application can live with a gap or can repair it by itself.

The early UDP standard names two major uses: the name server and trivial file transfer Source 2সোর্স 2. UDP is IP protocol number 17 Source 2সোর্স 2.

সহজ English

Pick TCP when every byte must arrive, in order. Examples are a web page, a file, a database call, and a login. Pick UDP when speed matters more than perfect delivery. The application also needs to be able to live with a gap, or to repair it by itself.

The early UDP standard names two major uses: the name server and trivial file transfer Source 2সোর্স 2. UDP is IP protocol number 17 Source 2সোর্স 2.

বাংলা ব্যাখ্যা

প্রতিটি বাইট ক্রমানুসারে পৌঁছানো দরকার হলে TCP বেছে নিন। উদাহরণ: ওয়েব পেজ, ফাইল, ডেটাবেস কল এবং লগইন। নিখুঁত ডেলিভারির চেয়ে গতি বেশি জরুরি হলে UDP বেছে নিন। এর সঙ্গে অ্যাপ্লিকেশনকে ফাঁক মেনে নিতে পারতে হবে, অথবা নিজে সেটি মেরামত করতে পারতে হবে।

শুরুর দিকের UDP স্ট্যান্ডার্ড দুটি প্রধান ব্যবহারের নাম দেয়: নেম সার্ভার (name server) এবং ট্রিভিয়াল ফাইল ট্রান্সফার (trivial file transfer) Source 2সোর্স 2। UDP হলো IP প্রোটোকল নম্বর 17 Source 2সোর্স 2।

A real-life example

A learning platform has two parts. A student submits a quiz answer. This goes over TCP, because one lost or reordered byte could damage the answer. The same platform has a live video lesson. A video call usually prefers to skip a late frame and show the next one, because a frame that arrives too late is useless. That style of traffic is a good fit for UDP. This example is the tutorial's own text.

সহজ English

A learning platform has two parts. A student submits a quiz answer. This goes over TCP, because one lost or reordered byte could damage the answer. The same platform has a live video lesson. A video call usually prefers to skip a late frame and show the next one. A frame that arrives too late is useless. That style of traffic is a good fit for UDP. This example is the tutorial's own text.

বাংলা ব্যাখ্যা

একটি লার্নিং প্ল্যাটফর্মের দুটি অংশ আছে। একজন স্টুডেন্ট কুইজের উত্তর জমা দেয়। এটি TCP দিয়ে যায়, কারণ একটি বাইট হারালে বা ক্রম বদলালে উত্তর নষ্ট হতে পারে। একই প্ল্যাটফর্মে একটি লাইভ ভিডিও লেসন আছে। ভিডিও কল সাধারণত দেরিতে আসা ফ্রেম বাদ দিয়ে পরেরটি দেখাতে চায়। খুব দেরিতে আসা ফ্রেম অকেজো। এই ধরনের ট্রাফিক UDP-র জন্য ভালো মানায়। এই উদাহরণটি টিউটোরিয়ালের নিজস্ব লেখা।

Trade-offs

TCPUDP
ConnectionHandshake firstNone
DeliveryReliable, in order Source 1সোর্স 1Not guaranteed Source 2সোর্স 2
OverheadMore messages and stateVery little Source 2সোর্স 2
Typical fitPages, files, transactionsLive media, quick lookups

The Overhead cell of TCP and the last row are the tutorial's own summary.

সহজ English

The Overhead point of TCP and the last point are the tutorial's own summary.

বাংলা ব্যাখ্যা

  • কানেকশন। TCP আগে হ্যান্ডশেক করে। UDP-তে কোনো হ্যান্ডশেক নেই।
  • ডেলিভারি। TCP নির্ভরযোগ্য এবং ক্রমানুসারে Source 1সোর্স 1। UDP-তে নিশ্চয়তা নেই Source 2সোর্স 2।
  • ওভারহেড (overhead)। TCP-তে বেশি মেসেজ এবং স্টেট (state) আছে। UDP-তে খুব কম Source 2সোর্স 2।
  • সাধারণ মানানসই ক্ষেত্র। TCP মানায় পেজ, ফাইল এবং ট্রানজেকশনে। UDP মানায় লাইভ মিডিয়া এবং দ্রুত লুকআপে।

TCP-র ওভারহেডের পয়েন্ট এবং শেষ পয়েন্টটি টিউটোরিয়ালের নিজস্ব সারসংক্ষেপ।

Common mistakes

  • "UDP is broken." UDP does what it says. The missing promises are the design Source 2সোর্স 2.
  • "TCP means the message was processed." TCP only delivers bytes to the other program. The program can still fail to handle them.
  • Mixing up a slow network with a lost connection. A slow reply is not always a failed one. Test both, and check what the user sees.
  • Forgetting that the server needs the port to be open. A closed port or a firewall rule can stop a connection even when the server runs. This is the tutorial's own advice, not a statement of the RFCs.

সহজ English

  • "UDP is broken." UDP does what it says. The missing promises are the design Source 2সোর্স 2.
  • "TCP means the message was processed." TCP only delivers bytes to the other program. The program can still fail to handle them.
  • Mixing up a slow network with a lost connection. A slow reply is not always a failed one. Test both. Check what the user sees.
  • Forgetting that the server needs the port to be open. A closed port or a firewall rule can stop a connection even when the server runs. This is the tutorial's own advice, not a statement of the RFCs.

বাংলা ব্যাখ্যা

  • "UDP ভাঙা।" UDP যা বলে তা-ই করে। প্রতিশ্রুতি না থাকাই এর নকশা Source 2সোর্স 2।
  • "TCP মানে মেসেজ প্রসেস হয়েছে।" TCP শুধু অন্য প্রোগ্রামে বাইট পৌঁছে দেয়। প্রোগ্রাম সেগুলো সামলাতে ব্যর্থ হতেও পারে।
  • ধীর নেটওয়ার্ক আর হারানো কানেকশন গুলিয়ে ফেলা। ধীর উত্তর মানেই ব্যর্থ উত্তর নয়। দুটোই টেস্ট করুন। ইউজার কী দেখে তা দেখুন।
  • সার্ভারের জন্য পোর্ট খোলা লাগে, তা ভুলে যাওয়া। সার্ভার চললেও বন্ধ পোর্ট বা ফায়ারওয়াল রুল (firewall rule) কানেকশন আটকাতে পারে। এটি টিউটোরিয়ালের নিজস্ব পরামর্শ, RFC-র বক্তব্য নয়।

What a tester can check

Tutorial advice

This advice is the tutorial's own. It is not from a standard.

  • Test with a bad network: add delay, packet loss, and a dropped connection. Check that the app shows a clear message and does not hang.
  • For a TCP-based feature, cut the connection in the middle of a request. Check that nothing is saved twice and nothing is half saved.
  • For a UDP-based feature, check that the app copes with a lost, late, or duplicate message.
  • Use a packet tool to look at the handshake, and see when connections open and close.
  • Check timeouts: what does the user see when the server is slow, and when the port is closed?

সহজ English

This advice is the tutorial's own. It is not from a standard.

  • Test with a bad network: add delay, packet loss, and a dropped connection. Check that the app shows a clear message and does not hang.
  • For a TCP-based feature, cut the connection in the middle of a request. Check that nothing is saved twice and nothing is half saved.
  • For a UDP-based feature, check that the app copes with a lost, late, or duplicate message.
  • Use a packet tool to look at the handshake. See when connections open and close.
  • Check timeouts. What does the user see when the server is slow? What does the user see when the port is closed?

বাংলা ব্যাখ্যা

এই পরামর্শ টিউটোরিয়ালের নিজস্ব। এটি কোনো স্ট্যান্ডার্ড থেকে নেওয়া নয়।

  • খারাপ নেটওয়ার্ক দিয়ে টেস্ট করুন: ডিলে (delay), প্যাকেট লস (packet loss) এবং ছিন্ন কানেকশন যোগ করুন। দেখুন অ্যাপ স্পষ্ট মেসেজ দেখায় এবং আটকে যায় না।
  • TCP-ভিত্তিক ফিচারে (feature) রিকুয়েস্টের মাঝখানে কানেকশন কেটে দিন। দেখুন কিছু দুবার সংরক্ষিত হয়নি এবং কিছু অর্ধেক সংরক্ষিতও হয়নি।
  • UDP-ভিত্তিক ফিচারে দেখুন অ্যাপ হারানো, দেরিতে আসা বা ডুপ্লিকেট মেসেজ সামলাতে পারে।
  • প্যাকেট টুল দিয়ে হ্যান্ডশেক দেখুন। কখন কানেকশন খোলে ও বন্ধ হয় তা দেখুন।
  • টাইমআউট পরীক্ষা করুন। সার্ভার ধীর হলে ইউজার কী দেখে? পোর্ট বন্ধ থাকলে ইউজার কী দেখে?

Key words

WordMeaning
TCPA reliable, in-order byte stream between two programs
UDPA simple message service with no delivery guarantee
SegmentOne piece of a TCP stream, sent inside an IP datagram
DatagramOne UDP message
PortA 16-bit number that picks the program on a computer
Three-way handshakeThe set-up of a TCP connection
SYN, ACK, FIN, RSTTCP flags: start, confirm, finish, reset
WindowHow much data the receiver can accept now
RetransmissionSending lost data again
TIME-WAITA short wait after close, to avoid mixing old and new connections

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    RFC 9293: Transmission Control Protocol (TCP)

    IETF · accessed 2026-10-22দেখা হয়েছে: 2026-10-22

  2. [2]
    RFC 768: User Datagram Protocol

    IETF · accessed 2026-10-22দেখা হয়েছে: 2026-10-22