# Basic Networking Concept **Protocol 協定** 用協定好的格式去傳送資料 **HTTP 超文本傳輸協定** Hyper Text Transfer Protocol **HTTP request** client > request > server client < response < server 1. 瀏覽器 HTTP request 到 server 2. server 處理後,回傳一個 response (html 標籤)回來,經過瀏覽器渲染出網頁 **DNS Server** Domain Name System client > 詢問某個網址的 IP 位置 > DNS server client < 回傳IP < DNS server _ > 永遠不要忘記瀏覽器只是另一個程式 _ **HTTP Status code** 1** Hold on 2** Here you go 3** Go away 4** You fucked up 5** I fuckd up _ **試作一個小 sever** ``` var http = require('http') var server = http.createServer(handleRequest) function handleRequest(req, res){ console.log(req.url) res.write('hello') res.end() } server.listen(5000)//port ``` _ **簡易理解由下到上的傳輸結構:** _________________________________ HTTP,FTP 紙條內容(協議格式) _________________________________ TCP 傳紙條的三次握手確認(會很確定有傳輸成功) / UDP 不確認,一直傳紙條(比較快但不確定) _________________________________ IP 寄紙條,寫收件者跟寄件人 _________________________________ 實體層 郵差幫忙寄信 _________________________________ _ **API** application programming interface 應用程式介面 透過 API 讓雙方交換資料 **JSON** JavaScript Objet Notation 內建轉成 Json 格式 `const json = JSON.parse(body)` 把物件變成 json 格式的字串 `console.log(JSON.strungify(obj))` _ 小實作一下 ``` const request = require('request'); const process = require('process') request( 'https://reqres.in/api/users/2', function (error, response, body) { const json = JSON.parse(body) console.log(json) } ) ``` _ SOAP simple object access protocol 交換都透過 html _ RESTful 是一種 style _ 必學指令 **curl** 抓下整個 html 檔 **nslookup** 看 IP 位置 **ping** 看連不連的到那個主機 **telnet** 連結port 看有沒有開啟,也可以拿來傳資料。最知名只用 telnet 的就是 PPT _ > 網路就是用來溝通跟傳送資料而建設的,標準化跟協定格式,就是便於更快更大型的傳送和溝通,網路的工程師就必須了解這些格式與標準
×
Sign in
Email
Password
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