Linux Networking & TCP/IP for Developers · 강의

TCP 및 UDP 기초

TCP(신뢰성 있고 연결 지향적)와 UDP(신뢰성이 낮고 비연결 지향적)의 차이를 구분하고, 애플리케이션별 사용 사례를 이해합니다.

레슨 3/412개 단계

TCP 및 UDP 기초은(는) CoddyKit의 무료 Linux Networking & TCP/IP for Developers 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Linux Networking & TCP/IP for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Linux Networking & TCP/IP for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Meet TCP and UDP

When data travels across a network, it uses different rules or 'protocols'. At the Transport layer of the TCP/IP model, two main protocols handle how applications send and receive data: TCP and UDP.

They both move data, but they do it in fundamentally different ways, each suited for specific tasks.

TCP: The Reliable Partner

TCP stands for Transmission Control Protocol. Think of TCP as a very careful post office that guarantees your letter will arrive, in order, and without errors.

  • It's connection-oriented: A connection must be established before data is sent.
  • It's reliable: It guarantees delivery of data.
  • It ensures ordered data transfer and error checking.

TCP's Connection Handshake

Before TCP sends any application data, it performs a 'three-way handshake' to establish a connection:

  1. SYN (Synchronize): Client asks to connect.
  2. SYN-ACK (Synchronize-Acknowledge): Server acknowledges and agrees.
  3. ACK (Acknowledge): Client acknowledges, and the connection is ready.

This handshake ensures both sides are ready to communicate reliably.

TCP: Guarantees Delivery

TCP uses several mechanisms to ensure reliability:

  • Acknowledgements (ACKs): The receiver sends ACKs for data received. If no ACK, the sender retransmits.
  • Sequence Numbers: Data packets are numbered to ensure they arrive in the correct order and to detect missing packets.
  • Flow Control: Prevents a fast sender from overwhelming a slow receiver.
  • Congestion Control: Manages network traffic to avoid overloading the network.

TCP Client: A Brief Look

This Python code snippet shows how a TCP client socket is created and attempts to connect. Notice the SOCK_STREAM type, which signifies TCP.

Run it to see the connection attempt!

import socket

# Create a TCP (Stream) socket
# AF_INET for IPv4, SOCK_STREAM for TCP
tcp_client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# Attempt to connect to a server
# This establishes the 3-way handshake
server_address = ('localhost', 8080)
print(f"Attempting TCP connection to {server_address[0]}:{server_address[1]}...")

try:
    tcp_client_socket.connect(server_address)
    print("TCP connection established.")
    message = b"Hello TCP!"
    tcp_client_socket.sendall(message)
    print(f"Sent: '{message.decode()}'")
    # In a real app, you'd also receive a response here
except ConnectionRefusedError:
    print("Connection refused. No TCP server running at that address.")
except Exception as e:
    print(f"An error occurred: {e}")
finally:
    tcp_client_socket.close()
    print("TCP socket closed.")

UDP: The Fast Messenger

UDP stands for User Datagram Protocol. Unlike TCP, UDP is like sending a postcard: you send it, and you hope it arrives, but there's no guarantee or tracking.

  • It's connectionless: No connection is established before sending.
  • It's unreliable: No guarantees of delivery, order, or error-free transmission.
  • It prioritizes speed and low overhead over reliability.

UDP: No Handshake, No ACKs

The simplicity of UDP comes from its lack of features:

  • There's no three-way handshake to set up a connection.
  • There are no acknowledgements (ACKs) for received data.
  • There's no retransmission of lost packets.
  • There's no built-in flow or congestion control.

This means less overhead, making it much faster for certain applications.

UDP Client: A Brief Look

This Python code demonstrates a UDP client sending data. Notice the SOCK_DGRAM type, which indicates UDP. Because it's connectionless, it can send data directly.

Run it to see a UDP datagram being sent!

import socket

# Create a UDP (Datagram) socket
# AF_INET for IPv4, SOCK_DGRAM for UDP
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# UDP is connectionless.
# You can send data directly without establishing a connection.
target_address = ('localhost', 9090)
message = b"Hello UDP!"
print(f"UDP socket created.")
print(f"Sending '{message.decode()}' to {target_address[0]}:{target_address[1]}...")

# Send the data
udp_socket.sendto(message, target_address)

print("UDP datagram sent.")
udp_socket.close()
print("UDP socket closed.")

TCP vs. UDP: The Core Differences

Here's a quick comparison of the two:

  • Connection: TCP is connection-oriented; UDP is connectionless.
  • Reliability: TCP guarantees delivery; UDP offers best-effort delivery.
  • Order: TCP ensures ordered data; UDP does not.
  • Speed: UDP is generally faster due to less overhead; TCP is slower due to reliability mechanisms.
  • Overhead: TCP has higher overhead; UDP has lower overhead.

When to Use TCP or UDP?

Choosing between TCP and UDP depends on your application's needs:

  • Use TCP for: Web browsing (HTTP/HTTPS), Email (SMTP, IMAP, POP3), File Transfer (FTP), Secure Shell (SSH). When data integrity and order are critical.
  • Use UDP for: Online gaming, Video/Audio streaming, Voice over IP (VoIP), Domain Name System (DNS). When speed and low latency are more important than guaranteed delivery.

Quick Check: Protocol Choices

Based on what you've learned, which of the following statements correctly describe UDP?

Recap: TCP & UDP Essentials

You've explored the fundamental differences between TCP and UDP!

  • TCP is reliable, connection-oriented, and ensures data integrity and order, but with higher overhead.
  • UDP is fast, connectionless, and has low overhead, but offers no delivery guarantees.

Understanding these distinctions is crucial for designing and troubleshooting network applications. Next, you'll apply these concepts to real-world scenarios!

무료로 시작

AI 튜터와 함께 Linux Networking & TCP/IP for Developers을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“TCP 및 UDP 기초” 강의는 무료인가요?

네 — “TCP 및 UDP 기초” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Linux Networking & TCP/IP for Developers 강의 전체를 잠금 해제할 수 있습니다. Linux Networking & TCP/IP for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.

“TCP 및 UDP 기초”에서 뭘 배우나요?

TCP(신뢰성 있고 연결 지향적)와 UDP(신뢰성이 낮고 비연결 지향적)의 차이를 구분하고, 애플리케이션별 사용 사례를 이해합니다. 브라우저에서 직접 실행하는 실습 코드로 Linux Networking & TCP/IP for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Linux Networking & TCP/IP for Developers을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Linux Networking & TCP/IP for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“TCP 및 UDP 기초” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Linux Networking & TCP/IP for Developers 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Linux Networking & TCP/IP for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. TCP/IP 모델 이해
  2. IP 주소 지정 및 서브넷팅
  3. TCP 및 UDP 기초
  4. ICMP와 Ping 및 Traceroute의 역할
← Linux Networking & TCP/IP for Developers(으)로 돌아가기