UULi
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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
    • Make a copy
    • 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 Make a copy 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    12
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 計算機網路筆記-ch2 ## HTTP HTTP 使用 <font color=red>**TCP,Port 80**</font> 1. client 會先 initiates TCP connection to server。 2. server會同意TCP connection from client 3. HTTP messages 可以開始交換於browser(HTTP client) 與 Web server(HTTP server)之間 4. TCP connection 關閉 HTTP的每次連線皆為獨立,不會每一次維持的狀態與資訊 ### Non-persistent HTTP 1. TCP連線開始 2. 最多只傳<font color=red>**1**</font>個Object 3. TCP連線關閉 當要下載數個objects時,就要request數次。 RTT(Round-trip Time) : time for a small packet to travel from client to server and back non-persistent HTTP 的response time = 2RTT+file transmission time ![](https://i.imgur.com/ojWAh83.png) ### Persistent HTTP 1. TCP連線開始 2. 在一次TCP連線中傳遞<font color=red>**數個**</font>objects 3. TCP連線關閉 persistent HTTP 的傳輸 = 一次的RTT(開啟connextion) + 每個objects的request and recieve的RTT + file transmission time ### Request message(ASCII明文) **Post** : 提交資料,請求處理 **GET** : 1. 請求展示指定資源 2. 指應用於request data **HEAD** : request與get相同的response,但沒有response message 中的 body **PUT** : 更新server的object (可能會被管理員關閉此權限) ### Response status codes ![](https://i.imgur.com/8b5Npc1.png) ## Cookies (1) a cookie header line in the HTTP response message; (2) a cookie header line in the HTTP request message; (3) a cookie file kept on the user’s end system and managed by the user’s browser; and (4) a back-end database at the Web site. ![](https://i.imgur.com/Uz8FL36.png) cookies會夾帶著http的request與response中, can be use for 認證、購物車、推薦。 ## WEB Caching(aka Proxy server) ![](https://i.imgur.com/AGHt5vx.png) client發出request時,會先傳給proxy,如果欲拿到的objects已曾經cached在proxy中,則會直接從proxy傳遞那些objects,如果沒有才會request origin server. 1. 減少request時間,proxy比較靠近client 2. 比較便宜,當今天因為網路頻寬不足導致queuing,解決方式1,換大一點的頻寬與網速,但太貴了;所以我們能在我們自己的區域網路(ex:公司or學校)建立一個proxy server,假設cache hit rate不低(ex:0.4),這樣就能大大地減少使用區域網路至網際網路的頻寬了。 ![](https://i.imgur.com/52vZIRa.png) ### Conditional GET proxy在一次http request時,都會先將objects caches下來,同時也會將if-modified-since的值存下來。日後假如又用相同的http request,則會先用get去確認if-modified-since是否一樣,如一模一樣,則會傳回status 304(Not Modified),並從cache傳objects給client;如果不一樣,則會再將objects放入body傳回給client(status為200 OK). ![](https://i.imgur.com/wnCcsTU.png) ## HTTP1.1 vs HTTP/2 ### http/2 大致上都跟http1差不多,但傳輸上有著很大的不同。 http1.1在傳送objects時有著FCFS(first-come-first-service), 所以當今天有著很大的object在進行TCP傳遞時,後面己的小objects都會因為前面大objects的傳送而被堵住,稱為Head of Line (HOL)blocking。 而http/2大大改善了這一點,http/2 divide objects into feames,然後再schedule frames(像是round robin). ![](https://i.imgur.com/x0bxeZQ.png) ![](https://i.imgur.com/dBeCWFm.png) ### HTTP/3 Http/3 adds <font color=red>**security**, **per object error- and congestion control**</font> (more pipelining) over UDP ## E-mail ### SMTP(Simple Mail Transfer Protocol) user agents, mail servers(mail box, message queue) The client SMTP will establish a TCP connection to port 25 at the server SMTP. 1. 無論是傳遞信件,或是接受信件皆由SMTP server完成,而不是透過個人電腦。 2. three phases of transfer 1. SMTP handshaking (greeting) 2. SMTP transfer of message 3. SMTP closure 3. commands : ASCII text(明文) 4. response : status code and phrase 5. ![](https://i.imgur.com/z9SlHTz.png) ### user agent ### mail server mail server裡面含有message queue與mail box,mail server就像是郵局一樣可以寄信與幫大家收信。大家想要寄出的信件會排入message queue裡等待送出,而mail box則是存入被寄件用戶們的信件,用戶可以利用user agent查看信件、刪除信件。 ![](https://i.imgur.com/35pUk1K.png) ### SMTP與HTTP的比較: SMTP是<font color=red>**push protocol**</font>,即TCP連線是由想要送出檔案的主機所建立 HTTP是<font color=red>**pull protocol**</font>,即TCP連線是由想要接收檔案的主機所建立 1. both have ASCII command/response interaction, status codes 2. HTTP : <font color=red>each</font> object encapsulated in its own response message 3. SMTP : <font color=red>multiple</font> objects sent in multipart message 4. SMTP uses persistent connection 5. SMTP 只能用7-bit ASCII 6. SMTP 用"."做結尾 ### Mail access protocol SMTP 、 IMAP(比SMTP更多功能) 、 HTTP(ex:gmail、Hotmail) ## DNS services ### Hostname-to-IP-address translation ### Host aliasing(主機別名): 一台主機可有多個別名(當然也有正規主機名稱canonical hostname 通常不好記)。 ### Mail server aliasing: Mail server的正規主機名稱可能不好記,可以給別名,dns可由別名找出正規的主機名稱及ip。 ### Load distribution: 有些網站是由許多的伺服器組成,每個伺服器都有各自的IP,DNS可以將所有該網站的伺服器的ip都對上同一個host name。這樣就不會讓所有的request都集中在一台伺服器處理,而是可以分散的讓所有的電腦處理。 ## DNS伺服器架構 DNS server是distributed and hierarchical的database。 ![](https://i.imgur.com/wIdPY6a.png) ### Root Root name servers provide the IP addresses of the TLD servers. ![](https://i.imgur.com/USkbMv3.png) ### TLD(Top Level Domain) such as com, org, net, edu, and gov, and all of the country top-level domains such as uk, fr, ca, and jp. TLD servers provide the IP addresses for authoritative DNS servers. ### Authoritative Every organization with publicly accessible hosts (such as Web servers and mail servers) on the Internet must provide publicly accessible DNS records that map the names of those hosts to IP addresses. 如:今天要request嘉義大學的圖書館(https://www.ncyu.edu.tw/lib/),則需先在local dns上找,找不到的話就會query root dns,root dns 會response .edu dns server的IP, 接著再去query .edu dns server,他則會response ncyu.edu.tw的DNS,最後再query ncyu.edu.tw得到圖書館網站的IP位置。 ### Local DNS server(another important type) Each ISP has a local DNS server (also called a default name server). Local DNS server通常會是個非常靠近使用者的dns伺服器,也通常會是預設的伺服器。每當local dns 沒有找到你要的網域名稱,才會去root找,找完再將結果存起來供下一次可以快速地尋找。 ## Iterated vs. recursive query ### Iterated query ![](https://i.imgur.com/s2fz46C.png) ### recursive query ![](https://i.imgur.com/cbmafDr.png) ## DNS CACHING dns 可以 caching 一些已查過的IP,這可以大大的加速response time,但是這是有時效限制的。 1. Cache entries timeout(disappear) after some time(TTL)(time to live). 2. TLD servers typically chased in local name servers. ## DNS records resource records (RR) 格式: (name, value, type, TTL) ### Type=A : name 是canoncial(正規)主機名稱 , value 是canoncial主機名稱為name的IP address ex:(relay1.bar.foo.com , 145.37.9.126 , A) ### Type=CNAME : name 是主機的alias(別名) , value 是alias為name的正規主機名稱 ex:(foo.com , relay1.bar.foo.com ,CNAME) ### Type=NS : name 是 domain(網域名稱) (e.g. foo.com) , value 是該Authoritative DNS server 名稱 (此Authoritative(官方) DNS server會去取得該網域內的主機ip位置) ex:(foo.com , dns.foo.com , NS) ### Type=MX : name 是主機別名 ,value 是主該mail server正規名稱 ex:(foo.com , mail.bar.foo.com , MX) ## Peer-to-peer(P2P) ### 優缺點 優點 : 大量user有資料需求,不會導致server崩潰,因為每個peers可以是server,也可以是client。具有scalability。 缺點 : 管理複雜。 ## P2P File Distribution 每個peer都可以提供自己的capacity來幫助server來distribute 檔案,不同於client-server的模式,在分配檔案時,server不需要copy每一份檔案給peers,反之,只要其中一個peer擁有檔案之後便可以透過此peer重新再分配檔案到其他peers。 ### C-S架構下的傳輸時間 ![](https://i.imgur.com/p7e3tXU.png) ### P2P結構下的傳輸時間 ![](https://i.imgur.com/teCxD7R.png) #### 兩者間的比較 ![](https://i.imgur.com/FrVpnHA.png) ### BitTorrent 會將資料切成256kb為單位的chunks。 而在torrent中的peer可以互相傳遞對方所需或是自己所需的chunks(資料的一部分)。 每個peer不需要擁有整個資料,也能湊出一個完整的資料給有需求的peer。 Tracker : tracks peers participating in torrent Torrent : group of peers exchanging chunks of a file user可以透過向tracker註冊成為torrent裡的peer, tracker會整理大家的IP,在需要的時候傳遞給有需求的peer做TCP connection。 當user獲得了想得到的檔案後,可以選擇selfishly的脫身, 也可以altruistically選擇留下來,將資料上傳給其他有需要的peers。 tit-for-tat(針鋒相對): peer可以選擇性的貢獻,但假如一昧地享有資源而不貢獻,可能會被其他peers報復。 相對地,願意分享的,其他peers也相對會願意跟她分享。 Optimistically unchoke : 每隔10秒鐘,節點就會給那些對自己所擁有的文件塊感興趣的節點進行評估,從而決定它向哪些節點傳遞數據(預設的配置是允許同時最多給4個節點發送數據)。根據tit-for-tat演算法,節點會優先選擇那些向自己上傳數據速率最快的節點,同時阻塞所有其它的鄰居節點。為了提高整體性能,BT還採用了一種叫做“Optimistic unchoke"的演算法。也就是除了上述的四個節點之外,它還會在其它的節點中隨機選取一個節點向其傳遞。 ## Video streaming CDN : Content delivery network ### Multimedia Video 會利用影片特別的編碼來降低冗餘的bits, Spatial : 假如圖片中有一欄或一列重複的位元,會用類似(N*red)來代替N個3byte的儲存。 Temporal : 因為影片中圖與圖中常有重複的地方,則只需要儲存有更改的地方的資訊就好。 CBR : Constant bit rate ,有固定的編碼方式,每秒的資料大小固定。 VBR : Variable bit rate ,會藉由Spatial與Temporal等方式編碼,bit per sec不固定。 ### Streaming stored video <font color=red>During client video playout, playout timing must match original timing.</font> 但network delay是variable的(直接播放的話,可能突然delay變大就轉圈圈了),所以必須要client-side buffer與playout delay。 ![](https://i.imgur.com/7mB2n9P.png) DASH : Dynamic, Adaptive Streaming over HTTP Server : server會將影片分割為好幾個chunks,並且會編碼成不同rate(畫質影像速率,畫質越高,速率越快),並將檔案(分rate版本或是平均地)放進不同的nodes中,並提供不同chunks的URLs。 Client (決定方) : 定時測量CS間的頻寬,並選擇最符合的coding rate傳送,或是user可以自己決定要用哪一種畫質(rate)。 而Client的選擇是有intelligence的, 他需決定 1. when to request(避免buffer滿了) 2. what encoding rate to request(找出最符合CS之間頻寬的畫質) 3. where to request(越近越好,或是傳遞頻寬越快越好) <font color=red>Streaming video = encoding + DASH + playout buffering</font> ### CDNs 不建議Content provider使用single server,因為一但該server毀了就全毀了,然後也會造成擁塞,CS距離長短不一。 CDN分散式架構有兩種 : #### enter deep : push CDN servers deep into many access networks (close to user) (設大量的servers在access network(Ex:區域網路)) #### bring home : smaller number of larger cluster (約10個) in POPs (point-of-presence) near access nets (設少量servers在網路連接點) 入網點(POP,point-of-presence)是一個將網際網路從一個地方接到其他地方的存取點。POP必需有一個唯一的網際網路協定(IP)位址。 subscriber會先request Netflix的server,然後Netflix會request 該影片的manifest。 使用者再利用manifest去 CDN nodes上取得影片,並且挑選喜歡的畫質。 ![](https://i.imgur.com/O8JQUbI.png) ### OTT : "Over The TOP media services" OTT不需去建構與管理底層網路連線(皆是由ISP管理),所以需要跟ISP簽約買頻寬,甚至協調(因為有時候可能是OTT業者server建置不夠,使user卡卡的,但user都會跑來罵ISP業者)。 ## URL vs. URI URL 是路徑,URI 是資源實際位置。 URI:localhost:80/user/save URL:localhost:80/user 很清晰的就能看出要想找到 URI,必先找到它的 URL,這也就解釋了 URL 是 URI 的子集是啥意思了。只找到 URL 是不知道要做什麼的,只有找到 URI 才知道資源是啥,要幹些什麼事情。 ###### tags: `計算機網路`

    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
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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