d27 Network Programming

supplement:

Object-oriented three properties: encapsulation, inheritance, polymorphism

from JSON Import JSONEncoder, JSONDecoder
 Import JSON
 from datetime Import datetime, DATE 
RES = { ' C1 ' : datetime.today (), ' C2 ' : date.today ()}
 # A = datetime.today () 
# there is time in when the month, day, hour 
# b = date.today () 
# no date is the 
# Print (A) 
# Print (b) 
Print (json.dumps (RES))
example
# Appears given TypeError: Object of type 'datetime' IS Not the JSON Serializable 

# like sequences can be obtained content 
# note = cls parameter when using dumps of sequences if not set, the default JSONEncoder 
# json.JSONEncoder default view Method 
# Self o is passed for the object itself object 

class MyJson (JSONEncoder):
     DEF default (Self, o):
         IF the isinstance (o, datetime):
             # format time 
            return o.strftime ( ' %% Y-M-% D% X- ' )
         elif the isinstance (O, DATE):
             return o.strftime ( ' %% M-% Y-D ' )
         the else:
            return super().default(self,o)
res = {'c1':datetime.today(),'c2':date.today()}
print(json.dumps(res,cls = MyJson))
View Code

__call__

In the general category, the call is automatically executed when the object (both objects in parentheses) 

in the Yuan class, when you call the class object will automatically call the method __call__ yuan class, and the class itself as the first parameters passed, as well as a bunch of parameters behind 

after covering metaclasses call, this class will not be able to produce the object, you must call the Super (). __call__ to complete the creation of the object   and returns its return value 

usage scenarios: 

when you want to control the process of creating an object, it is covered __call__ method 

when you want to create a process control class, they cover the __init__ method
View Code

network programming

### network programming 

: the preparation process of network-based applications 

### software development framework 

c / s client / server client / server 

b / s browser / server browser / server 

b / s architecture is the essence of c / s architecture 

server: 24 hours uninterrupted service 

clients: always be able to access the data

  

To two computers communication, we must have two basic elements 

1. The physical connection media, including cable, radio, optical fiber, etc. 

2. protocols

 

OSI protocol

OSI: open System Interconnection Reference Model, Open Systems Interconnection Reference Model Communication

OSI model 

application layer 

presentation layer 

session layer 

transport layer, 

network layer, 

data link layer, 

a physical connection layer

 

Five model OSI 

application layer 

transport layer, 

network layer, 

data link layer, 

a physical connection layer

  

1. The physical connection layer

Based on the electrical signals transmitted binary number 010101 drama

 

Guess you like

Origin www.cnblogs.com/komorebi/p/11312099.html