Discover python network programming book, include the articles, news, trends, analysis and practical advice about python network programming book on alibabacloud.com
difference between routers and switches? What is domain name resolution? How to modify the local hosts file? What are the application scenarios and advantages of producer consumer models? What is a CDN? What is LVS and what is the role? What is the role of Nginx? What is the role of keepalived? What is the role of Haproxy? What is load balancing? What is RPC and application scenarios? The function and application of the Asynio module are briefly described . The function and application of the
1. Socket programmingSocket types include:--TCP socket and UDP socket.
The General Customer service Area mode.
--raw socket
Can be used for sniffing and injecting
2. C/S modec/S (client/server, client/server) mode, also known as C/s structure, is a model that grew up in the the late 1980s and is a kind of software system architecture. The key of C/s structure lies in the distribution of functions, some functions are performed on the front end machine (i.e. client), an
Python network programming-TCP and UDP socket usage example, pythonudp
This article describes the use of TCP and UDP socket in Python network programming. We will share this with you for your reference. The details are as follows:
This chapter introduces UDP programming, and for more information, refer to: Python Learning Guide
TCP is to establish a reliable connection, and both sides of the communication can send data in the form of a stream. In contrast to TCP connections, UDP is a non-connection-oriented protocol.When using the UDP protocol, there is no need to establish a connection, just need to know the other side's IP add
#data,addr = Srvsock.recvfrom (2048)6 7 if __name__=="__main__": 8Udpserver ()It is important to note that the quotation marks in the address tuple in the server indicate that a datagram can be accepted for any address, and the TCP example indicates that a connection originating at any address can be accepted.Client Side
Create a new datagram socket
Send and receive data
Instance:1 defudpclient ():2Address = ('localhost', 9527) 3Clisock =Socket.socket (socket.af_inet,
(" Please enter what to send:") # String type, Convert to bytes type by Msg.encode () encoding server_address = ("127.0.0.1", 8000) # IP Address and port number of the receiving server client_socket.sendto (Msg.encode (), server_address) Client_socket.close () 4.UDP client loops to accept data multiple timesImport= socket.socket (socket.af_inet, socket. SOCK_DGRAM)while True: = input (" Please enter what you want to send:") Server_ Address = ("192.168.79.127", 8000) client_so
UDP broadcast#Coding=utf-8Importsocket, Sysdest= ('', 7788)#create a UDP sockets =Socket.socket (socket.af_inet, socket. SOCK_DGRAM)#The socket that needs to send broadcast data is modified to set, otherwise the broadcast data cannot be sentS.setsockopt (socket. Sol_socket, SOCKET. so_broadcast,1)#send data to all computers on this network in the form of broadcastsS.sendto ("Hi", dest)Print "wait for each other to reply (press CTRL + C to exit)" while
close the socket so that a complete network communication is over - $ $ #the data received include the HTTP header and the Web page itself, we just need to separate the HTTP header and Web page, the HTTP header print out, the content of the Web page saved to the file -Header, html = data.split (b'\r\n\r\n', 1) - Print(Header.decode ('Utf-8')) the #to write the received data to a file: -With open ('sina.html','WB') as F:Wuyi f.write (HTML) the - ##
Specify Permissions GRANTS rights
Table Operations
Creating table Create tables
Delete Table drop tables
Clear Table Transcate
Creating a temporary table create temporary table
Automatic Incremental Auto INCREMENT
Primary KEY PRIMARY Key
FOREIGN Key FOREIGN Key
Constraint CONSTRAINT
ALTER TABLE
Data manipulation
New Data INSERT
Deleting data Delete
Updating Data Update
WHERE
JOIN
GROUP by
ORDER by
INSERT
socketimport os tran = Paramiko. Transport ((host,port)) #连接服务器, host and Port Custom tran.start_client () Default_path = Os.path.join (os.environ[' HOME '), '. SSH ', ' id_rsa ') key = Paramiko. Rsakey.from_private_key_file (Default_path) tran.auth_publickey (' root ', key) Chan = Tran.open_session () # Open a channel chan.get_pty () #获取一个终端chan. Invoke_shell () #激活器 f = open (' Log.log ', ' a ') #打开一个文件用于写入执行的 Operation while True: # Monitor user input and server return data # Sys.stdin proce
Add multi-threaded solutions to the server1. The service-side code is as follows:This version does not really play the role of multithreading, the main reason is T.join (), the future version will improve the problem * * *#!/usr/bin/python#!coding:utf-8ImportOs,sys,time fromSocketImport*ImportThreadingdefhandleclient (conn):Print '[INFO] handleclient is: {0}'. Format (Os.getpid ()) whileTrue:data= CONN.RECV (1024) if notData:Print '[INFO] hand
--version 1 Only completes communication between the server/client.1. Server-side code:#!/usr/bin/python#!coding:utf-8 fromSocketImport*ImportOs,sysif __name__=="__main__": #Defining Socketshostip='127.0.0.1'Port=2048sock=socket (Af_inet,sock_stream) Sock.bind ((Hostip,port)) Sock.listen (5) Print '[INFO] start listening {0}:{1}'. Format (hostip,port) whileTrue:#accept a connection from a clientCONN,ADDR =sock.accept ()Print '[INFO] have recived
(1) simple link with socketthe socket inside Python supports UDP, TCP, and interprocess communication . the socket can encapsulate what we want to send, send the past, and then back to the original appearance, in fact, network communication can understand that Chengdu is built on the socket, the following code is to demonstrate the use of the socket for simple links#要成一次通信, at least two people, that is, a s
This article mainly introduces the python network programming example and provides the client and server. if you need it, refer to the client.
The code is as follows:
If _ name _ = '_ main __':Import socketImport OSSock = socket. socket (socket. AF_INET, socket. SOCK_STREAM)Sock. connect ("localhost", 8001 ))Import timeTime. sleep (2)Sock. send ('1 ')Print sock
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.