My Github address

Notes on data Structures and Algorithms

Notes for geek Time iOS Developer Class

IOS large factory interview high frequency algorithm summary

Summary of iOS interview materials

Socket

HTTP vs WebSocket

  • HTTPRequest characteristics: Communication can only be initiated by the client. Therefore, in order to realize the push technology, many websites used polling technology
    • Polling is sent by the browser to the server at regular intervals, such as every secondHTTPRequest, and the server returns the latest data to the client
    • In order to save server resources and bandwidth, and to communicate more in real time,HTML5It appears in the specificationWebSocketagreement
  • WebSocketandHTTPBoth are application – layer protocols
    • Actually,TCPIt supports full-duplex communication (both clients and servers can send messages to each other).
    • justHTTP“Request-reply mode” limits TCP’s capabilities
  • Websockets use ports 80(ws://), 443(WSS ://) and can bypass most firewall restrictions
    • ws://example.com/wsapi
    • wss://secure.example.com/wsapi
  • withHTTPThe difference is,WebSocketYou need to establish a connection first
    • This makes theWebSocketBecome aStateful protocolAnd part of the state information can be omitted in subsequent communication
    • whileHTTPRequests may need to carry additional status information (such as authentication, etc.) with each request

WebSocket

  • WebSocketIs an application layer protocol based on TCP that supports full-duplex communication
    • In 2011, it was standardized by IETF to RFC 6455 and later supplemented by RFC 7936
    • Either client or server can send messages to each other
  • WebSocketThere are many application scenarios
    • Social subscriptions, stock fund quotes, sports updates, multimedia chat, multi-player games, etc

WebSocket – Establishes a connection

HTTPDNS

Cache

Response headers

  • Cache-ControlDecide whether to make a network request
  • Last-Modified,ETagThe decision is to return304or200

Cache-Control

Last-modified, ETag

Last-Modified vs ETag

If None – Match, If Modified – Since

How to use the cache