Network programming knowledge points

First, the network infrastructure

  • Purpose: Learning in the Future of web frameworks scene pave the way for future work

    • How to run two programs to transmit information?

      • By file

    • Two runs on two machines in how communication program?

      • via Internet

  • Web application development framework

    • C/S

      • Client client

      • server server

      • For example: Thunder qq browser fly autumn input method Baidu cloud pycharm git VNC spider games

    • B/S

      • browser browser

      • server server

      • For example: Taobao mailbox various games Baidu blog know almost watercress drawer Park

    • Entrance harmonization of procedures

    • Relationship between B / S and C / S architecture: B / S are special C / S architecture

  • NIC: It is a real presence in the computer hardware

  • mac: mac has a globally unique address on each piece of card

  • Switch: connecting multiple machines and help communicate the physical device, known only mac address

    • LAN switches communicate

      • Broadcast: send to all machines

      • Unicast: Send to a machine

      • Multicast: a set of machine to a

  • Protocol: between two physical devices to the content to be transmitted, the length of the order of a few conventions

  • ip address

    • 4 decimal point protocol ipv4 hexadecimal 32-bit 2

      • 0.0.0.0 - 255.255.255.255

    • ipv6 protocol six bits take the hexadecimal 2 128 hexadecimal

      • 0: 0: 0: 0: 0: 0-FFFF: FFFF: FFFF: FFFF: FFFF: FFFF

  • Public network ip: ip address to be accessible to everyone

    • Why did your friend's computer field we can not access?

      • Each ip address in order to be accessible to everyone, then this must be the ip address you apply

  • Network ip: ip address these intervals do not use a public network, the public network to avoid overlapping and internal network ip ip

    • 192.168.0.0 - 192.168.255.255

    • 172.16.0.0 - 172.31.255.255

    • 10.0.0.0 - 10.255.255.255

  • arp protocol: Get mac address ip address

    • Switch implemented

    • Use of broadcast and unicast

  • Gateway ip: net exports, an area outside the LAN to access a local area network have to go through routers and gateways

  • Segment: it refers to a segment address, or such as xxx0 xx0.0 or x.0.0.0

  • Subnet Mask: to determine whether the two machines on the same network segment

  • port: Port, 0-65535

    • ip address can be confirmed that a machine

    • ip + port confirm an application on one machine

Two, tcp / udp protocol

2.1 tcp protocol

  • Features:

    • Reliably, slow, full duplex communication

    • When the connection is established: three-way handshake

    • When disconnected: Four waving

    • After the connection is established

      • Each piece of information sent by the receipt has

      • To ensure data integrity, as well as retransmission mechanism

    • Long connection: the two sides will always occupy the port

    • IO (input, output) operation, the input and output memory is the relatively

      • write send - output

      • read recv - input

    • A data length capable of transmitting almost unlimited

  • Scenario:

    • Upload and download files

      • Send e-mail, network disk, cache, movies, etc.

  • Three-way handshake and waved briefly four times

    • Three-way handshake

      • accept accepted during waiting for a client connection

      • connect the client initiates a request syn link

        • If the ack response obtained while the server side will receive a server-side sent the link request syc

        • After the client-side reply ack, it established a link tcp protocol

      • Three-way handshake process and then the code is accept and connect together to complete, specific details are no longer reflected in socket

    • Four waving

      • the corresponding server and client side code have close Method

      • Each end of the operations are initiated by a close fin disconnect request, to give after 'disconnect confirmation ACK', may end at one end of the data transmission

      • If both ends initiate close, it is twice the request and reply twice, a total of four operations

      • May end the data transmission ends, it indicates a link is disconnected

2.2 udp protocol

  • Features:

    • Connectionless, fast

    • The message may be lost

    • Capable of transferring data length is limited, there is provided in accordance with the relationship between the data transmission device

  • Scenario:

    • Class instant messaging

      • qq, micro-channel, and the like flying autumn

  • The difference between tcp and udp protocol agreements

    • tcp protocol: is a connection-oriented stream, reliable, slow, full duplex communication

      • Http web mail file

    • udp protocol: is a datagram-oriented, connectionless, is not reliable, fast, to complete one, many, many-to-many communication protocols efficiently

      • Instant Messenger video online viewing

2.3 stick pack phenomenon

  • Definition: After execute multiple commands at the same time, the results are likely to only part in the implementation of other commands and receive to another part of the result of execution before, a phenomenon known as stick package

  • Cause sticky package: stick pack phenomenon has only TCP, UDP never stick package

    • TCP data transfer protocol

      • Unpacking mechanism tcp protocol

      • Stream-oriented communication characteristics

  • In both cases stick package will occur:

    • Case a caching mechanism, the recipient's

    • Caching mechanism in the case of two receiver

  • to sum up:

    • Stick pack phenomenon occurs only in tcp agreement

    • On the surface, stick package problem is because the cache mechanism features the sender and recipient, a stream-oriented communication protocol TCP

    • In fact, mainly because the recipient does not know the boundaries between news, do not know how many bytes of data caused by one-time extraction

  • Stick pack phenomenon tcp protocol

    • What is the stick pack phenomenon

      • It occurs at the transmitting end of the stick package

        • Since the two data transmission time interval shorter length data + small

        • Therefore, the information as the two information is sent by a protocol optimization mechanism out tcp

        • To reduce the tcp agreement "acknowledgment of receipt" of network latency

      • Then the receiving end occurs stick package

        • Since the data is transmitted in protocol tcp no boundary, too busy to receive a plurality of

        • Data will stick together in the cache receives the discharge kernel

      • Nature: receiving information boundary is not clear

    • Stick package to solve the problem

      • Custom protocol 1

        • First sends a header, the header 4 bytes in length, content is the byte length of the message to be sent

          • struct module able to pack all the figures are fixed into 4 bytes

        • And then send the message

      • Custom protocol 2

        • We used to do a special protocol to send a file

        • Length of the header byte sent first dictionary, then send dictionary (dictionary contains the file name, size), and then transmits the content file

Three, osi seven layer model / osi five agreements

3.1 osi seven layer model

  • Seventh layer: Application Layer

  • Sixth Layer: The presentation layer

  • The fifth layer: Session Layer

  • Fourth layer: the transport layer

  • The third layer: The network layer

  • Second layer: data link layer

  • The first layers: the physical

3.2 osi five agreements

The number of layers name   protocol The physical device
The fifth layer Application layer python code associated http/https/ftp/smtp协议  
The fourth layer Transport Layer port port-related tcp / udp protocol Four routers, four switches
the third floor Network layer ip address associated ipv4 / ipv6 protocol (Three) routers, three switches
Second floor data link layer mac address associated arp protocol NIC (second floor) switch
level one Physical Layer      

Guess you like

Origin www.cnblogs.com/zengyi1995/p/11329059.html