Read about learning python network programming, The latest news, videos, and discussion topics about learning python network programming from alibabacloud.com
After reading this section, I suddenly got to know some incomprehension issues in the python network programming learning Notes (1). at least I understood what happened to socket. Here, we will not take notes on the origin of socket and directly go to the topic.
1. create a socket
To create a socket object, you must u
the specified socket option
Example:>>> Import Socket>>> socket.gethostbyname (' www.baidu.com ')' 220.181.111.147 '>>> socket.gethostbyname (' www.126.com ')' 123.125.50.22 '>>> socket.getfqdn (' 123.125.50.22 ')' 123.125.50.22 'Here Getfqdn but can't return domain name?
5, processing errorsThe main thing about handling error exceptions is to use try, except statements. For example, modify the gopherclient.py in the Python
(for example, 80) to listen, creating the socket connection for each client connection. Because the server will have a large number of connections from the client, the server is able to differentiate between which client and which clients the socket connection is bound to. A socket relies on 4 items: server address, server port, client address, client port to uniquely identify a socket.However, the server also needs to respond to requests from multiple clients at the same time, so each connecti
Excerpt: Https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/ 001432004977916a212e2168e21449981ad65cd16e71201000TCP 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,UDP is a non-connection-oriented protocol .When using the UDP protocol, you do not need to establish a connection, just need to know the other side's IP address and port number , you can directly send packets. But I d
': Break Else: Conn.sendall (bytes (ret_str+'yes, okay.', encoding='Utf-8')) Print(address)ClientImportSocketobj=Socket.socket ()#Connect to ServerObj.connect (('127.0.0.1', 9999,)) STRs= OBJ.RECV (1024)#Receive server-side information, 1024 indicates the most to receive 1024 bytes, more than 1024 can not be received at a time to complete#The recv here is also blocked, after receiving information from the server, will continue to execute the following codePrint(Str
Learning book: "The Basics of Python network Programming" by John Goerzen, author
The first part of the bottom network learning
Python provides all the means to access the socket inte
This article mainly introduces the basic knowledge of python network programming. For more information, see John Goerzen, author of "python network programming Basics ".
Part 1 underlying net
Learning book: John Goerzen, author of python network programming Basics
Part 1 underlying network learning
Python provides all the methods to access the Socket interface of the underly
Theme
Client/server architecture
Socket: End of communication
Socket address
Connection-oriented and non-connected sockets
Network programming in Python
Socket module
Socket Object Methods
TCP/IP client and server
UDP/IP Client and server
Socketserver Module
Twisted Framework Introduction
Related modules
1
Reprint Please note: @ small Wuyi http://www.cnblogs.com/xiaowuyi
Learning book: John goerzen, author of Python network programming BasicsPart 1 underlying network learningPython provides all the methods to access the socket interface of the underlying operating system. Th
Learning book: John Goerzen, author of the basics of Python network programming
The first part of the bottom network learning
Python provides all the methods to access the socket inter
Recently, just after the internship, very much like the experimental building, but their own direction is still not sure, I think the space is very large, although already a senior person, think of others are busy to buy professional clothes, buy high-heeled shoes interview, learn makeup, look at themselves, instead began to slowly focus on sports, diet and skin care, haha, The programmer is Jiangzi, the body is the capital of revolution. Now the direction is at least determined, the data analys
','123456') . JSON ()#use the auth parameter to specify the account password for the authentication of the permission, Auth is a tuple Print(RES)#====== sending files =====URL ='Http://api.nnzhp.cn/uploadfile'Res= Requests.post (url,files={'file': Open ('api11.py') }). JSON ()#Specify files parameter, pass file, is a file object Print(RES)#===== Send header======URL ='Http://api.nnzhp.cn/getuser2'Data= {'userid': 1} header= {'Content-type':"Application/json"} res= Requests.post (ur
. To address these numbers conveniently, these numbers are referred to as ports. (This port is a logical port)
C: Transport protocol : rules for communication. For example: TCP, UDP protocol (like two people have to communicate in the same language)
①, udp:user Datagram Protocol User Datagram Protocol
Features: For no connection: the source and destination ports do not need to be connected before transmitting data, each datagram size is limited to 64K (8 bytes), and the unreliable protocol
, then numbering each IP packet, ensuring that the other party receives it sequentially, and automatically re-sends if the package is lost.
8) Many of the more advanced protocols are based on the TCP protocol, such as the HTTP protocol for the browser, the SMTP protocol for sending mail, and so on.
9) A TCP message contains both the source and destination IP addresses, the source and destination ports, in addition to the data to be transmitted.
10) What role does the port have? Wh
and downloading remote filesSftpclientFor connecting to a remote server and performing an upload downloadUpload and download based on user name password:Import Paramiko transport = Paramiko. Transport (' 172.16.2.234 ', ()) Transport.connect (username= ' root ', password= ' 123345 ') sftp = Paramiko. Sftpclient.from_transport (transport) # upload location.py to Server/tmp/test.pysftp.put ('/data/local/location.py ', '/data/ remote/test.py ') # download Remove_path to local local_pathsftp.get
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
Python is a powerful network programming tool for two reasons:1. There are many libraries in Python for common network protocols2. Python's advantages in processing byte streamsThis chapter mainly discusses some network modules in
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.