MaDi
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # [後端概念] OSI七層協定/TCP四層協定/三次握手/四次揮手 ###### tags: `後端` ## OSI七層協定,TCP/IP四層協定 ### OSI模型 >是一種制定網路標準都會參考的概念性架構,非一套標準。 ![](https://i.imgur.com/XQTEmkw.png) 而這個層與層之間,各自都會夾帶一個新的資料用作辨識,發送 request 的時候,由 應用層開始往下到傳送層,傳送層會加一些資料,然後再往下給網路層,網路層也會加一些資料,最後是到鏈結層,一樣也會加資料。然後再通過實體傳送到接收方,接收方在一層層由鏈結層開始往上一路到應用層,各次解析個層需要的資料。而伺服器回應的時候也是一樣,一層層往下包裝,接收的在一層層往上解析。就像下圖一樣。 * IP: 網路唯一的位置 * Domain: 網域/網址 * DNS(Domain Name Server): 經由 DNS,由Domain查到 IP 位置 ### TCP vs UDP >**TCP(通訊控制協定)** 和 **UDP(用戶資料包協定)** 都是網際網路中常見的協定,**它們負責在網際網路將資料從設備傳輸到伺服器**。當您使用 Skype 聊天、發送電子郵件、觀看直播或瀏覽網頁時,都會使用這兩種協定。 > >UDP 和 TCP 都會**將資料分隔成更小的單元進行傳輸。這些小單元稱為封包,封包中包含發送端和接收端的 IP 位址、各種配置、使用者傳送的實際資料等。** 1. TCP是一個**保證會把資料送達**的協定,**較可靠**。 * **TCP 為每個封包分配一個唯一的識別碼和一個序號**,這些號碼能讓接收端識別封包的完整性,以及封包的順序。 * **當接收端收到封包後,如果順序正確,會向發送端傳送一個確認信號(Acknowledgement),以此確認接收端已經收到封包。** * 發送端傳送下一個封包。 * **如果封包遺失或發送順序錯誤,接收端會保持沈默,不發送確認信號。這表示發送端需要重新傳送封包。** ![](https://i.imgur.com/e8Hdunk.png) * 優點: 因為資料是**按照順序發送**的,**有助於流量控制和解決資料壅塞的問題,並容易發現和修復錯誤。** 因此,**經由 TCP 發送的資料能完全到達目的地**。即使網路阻塞,傳輸的資料也不會出問題。 * 缺點: 發送端和接收端之間有很多往來的通訊,因此**建立連線和交換資料需要更多的時間。** 2. UDP則是**會一直發送資料,但不保證會送達,但較快速。** UDP較少用到。 * **UDP 不需要唯一識別碼和序號**就能完成相同的工作。 * 這種協定以**串流**方式傳送資料,**發送端不會等待接收端的確認信號,會繼續不斷發送封包資料。** * 也因此,UDP 幾乎**沒有錯誤修正功能,也不在乎封包遺失,因此很容易出錯**,但**傳輸速度比 TCP 更快**。 * **串流媒體、VoIP 語音、網路遊戲**等服務經常使用 UDP 協定,這網路應用不太需要可靠性機制,封包遺失不會導致服務中斷。 ![](https://i.imgur.com/R2eVXXl.png) ![](https://i.imgur.com/nejxCLH.png) ### TCP三次握手/四次揮手 >Step 1:TCP 三向交握 - 瀏覽器: 嘿 伺服器你在嗎? - 伺服器: 在唷! - 瀏覽器: 好的收到,那我要開始傳資料囉~ >Step 2:瀏覽器請求、資料傳輸、渲染畫面 - 瀏覽器,送出第一次請求(Resquest) - 伺服器,透過封包傳輸資料,每個封包上限約 1506 bytes。因此,一個請求可能會拆分成好幾個封包來回傳資源(Response) ** 封包就類似購物袋的角色,它會負責把資料拆分成好幾個封包來回傳資源(Response) ** - 瀏覽器,第一次渲染 >Step 3:TCP 四次揮手,結束連線 - 瀏覽器:好囉,資料都收到囉,可以關閉連線囉(申請關閉)。 - 伺服器:申請通過,那我也關囉。(回應瀏覽器說我收到關閉通知了) - 伺服器:告知關閉,本身也開始關閉。(主動告知瀏覽器說我不再接收數據) - 瀏覽器:收到關閉通知,回傳是否真正關閉,等候一段時間後,客戶端也關閉。 * TCP三次握手/四次揮手: https://hackmd.io/3-OHqc_1T6Gxytbv6VPfDA?view * TCP 和 UDP 是什麼:簡單的說明: https://nordvpn.com/zh-tw/blog/tcp-udp-bijiao/

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully