8.6 day27 network programming osi seven layer protocol module additional knowledge Time

Time Module additional knowledge


What date and datetime difference is?

date 就是年月日

datetime就是年月时时分秒

The following code will complain Why?

import json
from datetime import datetime,date

print(datetime.today())
print(date.today())
"""
TypeError: Object of type 'datetime' is not JSON serializable
"""

becausedatetime 和 data所传出的类型并不是json默认能处理的 不能被json序列化

principlejson 处理数据类型用的类是JSONEcoder 你不往dumps里面传cls的类 他就默认用JSONEcoder

JSONEcoder这个类的方法default 定义了他不能序列化时返回的内容

You can write a class to inherit their own JSONEcoder, and override the default method which

class MyJson(json.JSONEncoder):
    def default(self, o):
        if isinstance(o,datetime):
            return o.strftime('%Y-%m-%d %X')
        elif isinstance(o,date):
            return o.strftime('%Y-%m-%d')
        else:
            return super().default(self,o)
          
res = {'c1':datetime.today(),'c2':date.today()}
print(json.dumps(res,cls=MyJson))

# {"c1": "2019-08-06 20:38:50", "c2": "2019-08-06"}

The default method rewritten not only make the process json datetime.todat () and date.today ()

You can control the output in the form specified

network programming


Software development framework

c / s architecture (client / server)

c: Client

s: server

b / s architecture (browser / server)

b: Browser

s: server

ps: b / s architecture essentials is c / s architecture

Mobile terminal looks c / s architecture (ie client installed on the phone) more fire, in fact, b / s (ie the end of the phone APP acts as a browser, all service on the web page) has been rising.

Micro-channel Alipay are doing one thing: a unified interface

It is foreseeable that after the end of the phone is certainly the b / s more fire.

Service and client characteristics?

Server: 24-hour service

Client: When did want to experience the service, went corresponding server to request service

What learning network programming use, and the development of a b / s architecture software needs?

Learning Network programming can develop a c / s architecture software

Concurrency, database front-end, Django can develop a b / s architecture software

History of network programming

The earliest any advanced technology are derived from military

return to the past

  1. Early telephone phone line
  2. Big ass Internet line
  3. Laptop wireless phone

To achieve remote first need is: a physical connection media

People have to say in order to achieve smooth communication unified language

​ >>> 英文

To communicate between the remote computer and the computer is connected in addition to the physical medium further need

​ >>> 一套公共的标准/协议

Osi seven agreements

应表会传网数物

Application layer

Presentation layer

Session Layer

Transport Layer

Network layer

data link layer

Physical connection layer

Osi五层协议

Application layer

Transport Layer

Network layer

data link layer

Physical connection layer

1. The physical connection layer

010101 binary data based on the electrical signal transmission

2. Data Link Layer

a. predetermined electrical signal the grouping

b. any Internet-connected computer must have a network card

Each piece of card is engraved with a unique number in the world

12 hexadecimal

The top six vendors No.

After six line number

This 12-digit called mac address

ps: the above two points collectively referred to as "Ethernet protocol"

Switch

Ethernet-based communication protocols
can not communicate across local area networks

3. Network Layer

IP protocol

As long as the provisions of the computers connected to the Internet must have an IP address
ip address Features: dotted decimal
ip address minimum: 0.0.0.0
ip address maximum: 255.255.255.255
ip address There are two versions: IPV4 IPV6(Because not enough that the current IPV4 so there is a computer version launched IPV6)

IP地址是动态分配的

4. Transport Layer

Protocol TCP \ UDP port is based on the work of the
port (port)

In fact, between the computer and the computer is the communication between applications on the computer with the application

Port: An identifier for a computer on an application
range of port numbers: 0 to 65535
Note: 0 to 1024. These are the operating system default port number used
Recommendation: Use the port after the 8000
MySQL default port: 3306
Redis default port: 6379
Django default port: 8000
the Flask default port: 5000

The port number is dynamically assigned
for the first time since 8989 is assigned to qq
will start again qq closed port number might have changed

Summary
ip地址: An identifier for a computer to access the Internet
port端口: An identifier for an application on a computer
ip+port: uniquely identifies an application to access the Internet on a computer

The application layer

HTTP protocol

FTP protocol

TCP protocol

Streaming protocol, reliable protocol

TCP-based protocol channel

The reason why the TCP protocol to transmit data reliably, it is the use of two-way channel

Four waving three-way handshake

Three-way handshake to establish a connection

Four waving Disconnect

Guess you like

Origin www.cnblogs.com/PowerTips/p/11312089.html