Discover python network programming book, include the articles, news, trends, analysis and practical advice about python network programming book on alibabacloud.com
, PORT))8 9 whileTrue:Tenmsg = input (">>>:"). Strip () One ifLen (msg) = =0: A Continue - Client.sendall (Msg.encode ()) - thedata = CLIENT.RECV (1024) - - Print('Received', Data.decode ())First open the server, and then turn on client 1, client 2, in the client 1 input information can receive server response information, in the client 2 input information can not receive server response information, at this time disconnect client 1, client 2 can receive the service side of th
description
s.recv ()
receive TCP data
s.send ()
send TCP data
s.sendall ()
full send TCP Data
s.recvfrom ()
receive UDP data
s.sendto ()
send UDP data
socket function for public use
description
s.getpeername ()
The address of the remote end of the current socket is connected to
s.getsockname ()
First, Introduction:Python UDP is no connection, no TCP three handshake, error retransmission mechanism, hair, just send, collect, efficiency than TCP high, applied to the data frame is not high, such as video, audio transmissionSecond, the realization process:The server-side process is as follows:
1. Creating a UDP socket
2. Bind an interface to allow the client to connect
3. Acceptance of data
The client process is as follows:
1. Create a socket
2. Send
to other new clientsNewsocket, clientaddr =tcpsersocket.accept () whileTrue:#receive data sent from each other, maximum 1024 bytes receivedRecvData = NEWSOCKET.RECV (1024) #if the length of the received data is 0, it means that the client has closed the link ifLen (RecvData) >0:Print 'recv:', RecvDataElse: Break #send some data to the clientSendData = Raw_input ("Send:") newsocket.send (senddata)#closing the socket for this client service, as long as it is turne
clientNewsocket.send ("Thank you!")#closing the socket for this client service, as long as it is turned off, means that it can no longer serve the client, and if service is required, it can only reconnect againnewsocket.close ()#turning off the listener socket, as long as the socket is closed, means that the entire program can no longer receive any new client connectionsTcpsersocket.close ()TCP Client TCP client build processTCP client is much simpler than the server side, if the server is the
) sersocket.setsockopt (Sol_socket, SO_REUSEADDR,1) Localaddr= ("', 7788) Sersocket.bind (localaddr) Sersocket.listen (5) Try: whileTrue:Print('-----The main process, wait for the new client to arrive------') newsocket,destaddr=sersocket.accept ()Print('-----The main process, next create a new process responsible for data processing [%s]-----'%str (DESTADDR)) client= Thread (Target=dealwithclient, args=(NEWSOCKET,DESTADDR)) Client.start ()#Because this socket is shared in the thread,
Python network programming--io multiplexing EPOLL1, kernel Epoll model explainedThis section refers to the http://blog.csdn.net/mango_song/article/details/42643971 blog and organizesFirst, we define the concept of flow, a stream can be a file, socket,pipe, and so on can do I/O operations of kernel objects. Whether it's a file, a socket (socket), or a pipe, we can
(). Decode ("UTF-8")). Encode ("UTF-8")) Tcpserv = Server (ADDR, Myrequesthandler) #变动位置print (' Wait for a new connection .... ') Tcpserv.serve_forever ()MultithreadingSocketserverServer:From Socketserver import (TCPServer as TCP, Streamrequesthandler as srh,threadingmixin as TMI) #变动位置from time import C Time HOST = ' Port = 1234ADDR = (HOST, Port) class Server (TMI, TCP): #变动位置 passclass myreq
. 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
Today learned a Python network programming, feel relatively simple, that is, the basic steps, Create--bind---listen-->receive/send---->close.Also learn a TCP version of the server programming framework that can support multiple socket connections. The feeling is also possible. The simplest of these frameworks is Tcpser
special ip: 127.0.0.1 native ip 0.0.0.0 automatically use locally available network cards ip 192.168.1.0 represent network segments 192.168.1.1 typically gateway address 192.198.1.255 broadcast address port: value range 1~65535 1~255 Some general-purpose ports 256~1023 SystemsPorts 1024~65535 own ports linux command: ifconfig View native ip ping ip View Latency ps-aux View system pro
First, what is network programmingNetwork programming is simply to send the information to receive, intermediate transmission for the role of physical lines.Before we learned about network programming, the code that was written on the app was only available on its own, not interacting with others. So how do you communi
多的工作。包括 GitHub、Bitbucket[3]、Stack Overflow[4]、Reddit、Tumblr、Twitter[5][6]和 Tuenti[7]在内的知名网站,及亚马逊网络服务系统都使用了HAProxy。# 作用 负载均衡30. What is load Balancing?负载均衡 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽、增加吞吐量、加强网络数据处理能力、提高网络的灵活性和可用性。负载均衡,英文名称为Load Balance,其意思就是分摊到多个操作单元上进行执行,例如Web服务器、FTP服务器、企业关键应用服务器和其它关键任务服务器等,从而共同完成工作任务。# 重点拓展网络设备31. What are RPC and application scenarios?RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议。RPC协议假定某些传输协议的存在,如TCP或UDP,为通信程序之间携带信息数据。在OSI网络通信模型中,RPC跨越了
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.