Network programming-Multi-threading, Socketserver

Source: Internet
Author: User

What is the difference between Python2 and Python3?
""" Python3 native support for Unicode characters Python2 using ASCII as the default encoding causes string to have two types of STR and Unicode, and Python3 supports only Unicode string """ """ py2:    Unicode            v = u "root"     essentially in Unicode storage    (str/bytes)       v = "Root" is        essentially stored in bytes py3:    str                   v = "Root" is         essentially stored in Unicode    bytes              v = "Root" is         essentially stored in bytes "" " 
function scope

The scope of Python is broken down by functions, and scopes are generated as soon as the completion code is written.

The variables of the program in Python are not accessible in any location, and access permissions determine where the variable is assigned. The scope of the variable determines which specific variable name the program can access in that part.

There are 4 types of Python scopes:

L (local) local scope

E (enclosing) must be in a function outside the package function

G (Global) scope

B (built-in) built-in scopes

Find according to L->E->G->B rules

List-expression

A list expression is a powerful expression that builds a list in Python

Format: v = [Lambda x:x+i for I in range (10)]

Internet

DHCP service in routers or switches automatically assigns IP addresses: (DHCP; automatically assigns IP to computers within the LAN)

IP: With 4 "." Example of separate decimal notation: 192.168.13.11

ip:192.168.13.86

IPV4

00000000.00000000.00000000.00000000

0~255 0~255 0~255 0~255

IPV6 (at present, the basic personal use is not)

00000000.00000000.00000000.00000000.00000000.00000000

Subnet Mask: 255.255.255.0

192.168.13.86

255.255.255.0

The number of blocked IP digits as a network segment

As a variable value for the blocked part

Gateway: The interface in the router that connects the switch

Gateway ip:192.168.13.1 (default = 1)

The network consists of a LAN/Metro network/WAN

Dns

Network connection:

-Domain Name resolution

Www.luffycity.com ==> 47.95.64.113

Www.oldboyedu.com ==> 101.200.195.98

-Connection

  SK = Socket.socket ()

Sk.connect (' 47.95.64.113 ', 80)

Look at the above code, then the domain name and IP is the corresponding relationship where?

Local:

Win Local computer:

C:\Windows\System32\drivers\etc\hosts
  

DNS server: Top 13 DNS servers worldwide

Socketserverthreadingtcpserver Source Analysis:

  

First Knowledge thread
impor Timeimpor ThreadingdefTask (A1,A2,A3): Time.sleep (2)    Print("get The Courier .")defPlay ():Print('play with your girlfriend')deftake-out Food ():Print("go get takeout.")#Create a thread#get the thread to perform the task: functionT1 = Threading. Thread (target=task,args= ())#go do it.T1.start ()#Create a thread#get the thread to perform the task: functionT2 = Threading. Thread (target=play))#go do it.T2.start ()#Create a thread#get the thread to perform the task: functionT3 = Threading. Thread (target=take-Out food ))#go do it.T3.start ()Print("Play Fan")Print("Fanning the Flames")Print("Play Cheap ...")
Socket and thread mates
Import TimeImportSocketImportThreadingdefTask (conn): Time.sleep (5) Data= CONN.RECV (1024)    Print(data) conn.close () server=socket.socket () Server.bind ('192.168.13.86', 8000)) Server.listen (5) whiletrue:conn,addr=server.accept () T= Threading. Thread (target=task, args =(conn,)) T.start ()



Network programming-Multi-threading, Socketserver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.