Today's content:
Network Programming:
Software development structure
1, C / S architecture
s: server server
c: client client
client: refers to the application of the client, when in need of services to go to enjoy their favorite service
server: that is, 24 hours wait for the end of the service of others or provide services
2, B / S architecture
s: server server
b: browser browser, but also a client, but the client does not need you to install any application,
just in the browser resources (web resources) through HTTP request to the server-side related,
the client browser browser can be CRUD.
ps: micro-channel Alipay are doing the same thing: the same interface
to learn network programming purposes, the city is that you can develop a software architecture
to link the exchange of data between computers in order to better communications and more computers,
it must have a public the standard protocol in order to make the other party understand you send data, or to read more computers to manipulate the data,
at this time it is necessary to have a common standard protocol, namely OSI protocol, which is just one of the
OSI protocol
The application layer
represents a layer
session layer
transport layer,
network layer,
data link layer,
a physical connection layer
1, the physical connection layer: cable, Ethernet, fiber optic cable ....
is the transmission level of the electrical signal, i.e., the binary data 0110 of a pile
2, the data link layer:
1, a predetermined electrical signal grouping
2, any predetermined computer has a card, this card is inscribed with a number unique in the world
mac address by former 6 12 hexadecimal digits after the vendor number 6 is pipelined number
ps: the above two points collectively as the "Ethernet protocol"
switch: is Ethernet-based communications protocol, can not communicate across the LAN
Internet: a plurality of local area networks that are connected to each other from N
3, the network layer
ip protocol
provides access to the computer as long as the Internet must have an IP address
ip address characteristics: dotted decimal
ip address minimum: 0.0.0.0
ip address maximum: 255.255.255.255
ip address is currently available in two versions: IPV4 IPV6 (due IPV4 not enough representation of the existing computer so IPV6 launched version)
IP address is dynamically allocated
4, transport layer
TCP \ UDP-based protocol ports are working
port (port)
is actually an application with the application of the computer between the computer and the computer Communication
ports: used to uniquely identify an application on a computer
Port number range: 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 qq is assigned to
the qq shut down the port number may start again becomes the
TCP protocol: also known as streaming protocol, or reliable protocol
based on the TCP protocol communications Required to establish two-way channel
three times four waving handshake
The client sends a request to the server, this is the first handshake, a client before that has been in a listening state
after the server receives a request to respond to the client, and the client to take place together with information corresponding to the first the second handshake
When the client receives the data message, the server must send a message to give to receive success, that the server needs to receive the confirmation message, third handshake success! Establish links
Four waving, broken link
The client (or server) sends a request to the server first wave
The server sends an acknowledgment of receipt of the request after receiving the request to the client, the second wave
Since the client may receive a complete absence of data, the server has not been fully data are sent to the client, server and other data sent to the client process is completed, the third wave
The client then receive the service side of the break off links news link in the message to be sent to the server, the server is a confirmation message, disconnect the link, the fourth wave
But when messages are received within a certain time will not receive the client waits for the server to send, and send the data again for some time, until the end of time, to determine the client back or hung up, will be
Related data cleared off.
PS: IP Address: it is a computer that uniquely identifies the Internet access
port ports: one is used to uniquely identify the computer application
ip + port: an application that uniquely identifies the Internet on a computer
application layer: agreement HTTP protocol FTP protocol
knowledge points to add:
time type can not be converted directly into json string will complain, you must manually turn himself
Import json
from Import datetime datetime, DATE
#print (datetime.today ()) year, month, day, hour
# print (date.today ()) date
#isinstance determine whether an object is an instance of a class
#issubclass determine whether a class is a subclass of a certain class class or descendant class
class MyJson (json.JSONEncoder):
DEF default (Self, O):
IF the isinstance (O, datetime):
return o.strftime ( '%% Y-X-M-% D%')
elif the isinstance (O , DATE):
return o.strftime ( 'M-%%% Y-D')
the else:
return Super () default (Self, O).
# print (date.today ()) date
#isinstance determine whether an object is an instance of a class
#issubclass determine whether a class is a subclass of a certain class class or descendant class
class MyJson (json.JSONEncoder):
DEF default (Self, O):
IF the isinstance (O, datetime):
return o.strftime ( '%% Y-X-M-% D%')
elif the isinstance (O , DATE):
return o.strftime ( 'M-%%% Y-D')
the else:
return Super () default (Self, O).
# Call super (), the parent class has a default () This method
However, due to my own definition, so first search their property method
that is the parent class's default () method interception
thereby proving priority to find their own property, go to find the parent class, built,
RES = { 'C1': datetime.today (), 'C2': date.today ()}
Print (json.dumps (RES, CLS = MyJson))
However, due to my own definition, so first search their property method
that is the parent class's default () method interception
thereby proving priority to find their own property, go to find the parent class, built,
RES = { 'C1': datetime.today (), 'C2': date.today ()}
Print (json.dumps (RES, CLS = MyJson))