','Tracy','Sarah']: #Send data:s.send (data)PrintS.RECV (1024) S.send ('Exit') S.close ()Then we open two command-line windows, one running the server program, the other running the client program, you can see the effect.Note that the client program runs out, and the server program will run forever, you must press CTRL + C to exit the program.
Summary
Socket programming with TCP protocol is
This article mainly introduces Socket network programming in python, which has some reference value. if you are interested, please refer to it.
What is network?
A network is composed of nodes and connections, indicating many objects and their intercommunication. In mathematics, the network is a type of graph, which is generally regarded as a weighted graph. In
usage error, you can use the following code to prevent this situation1 phone.setsockopt (socket. Sol_socket, SOCKET. SO_REUSEADDR, 1)Four, when the client input is empty (that is, direct carriage return), press ENTER, the client has been across there,Cause Analysis:The client sends the empty information needs to call the operating system interface, the client program in memory to send the information to co
This article describes the use of Python for socket network programming, assuming that the reader has the basic knowledge of network programming and Python basic syntax knowledge, the code in this article, if not stated, is run under Pyt
the socket. S.setblocking (flag) If flag is 0, the socket is set to nonblocking mode, otherwise the socket is set to blocking mode (the default value). In nonblocking mode, if the call recv () does not find any data, or the Send () call cannot send the data immediately, the Socket.error exception is raised. S.makefile () Create a file associated with the socket3
Python socket network programming TCP/IP server and client communication, pythonsocket
Python socket network programming
I have bought two books, "python
()
Close the socket.
S.getpeername ()
Returns the remote address of the connection socket. The return value is typically a tuple (ipaddr,port).
S.getsockname ()
Returns the socket's own address. Typically a tuple (ipaddr,port)
S.setsockopt (Level,optname,value)
Sets the value of the given socket optio
Python development [Article 8]: socket network programming, python Article 8
Server:
Client:
Server output:
Client output:
Continuous sending information:
Server:
Client:
Run commands on the linux Client
Server:
Client:
File Sending in linux
Server:
Client:
Up to 32768 data records can be sent at a time (different syst
Python 3 Socket Programming one client/server architectureThe internet is the C/s architecture everywhere1, c/s structure, that is, client/server (client/server) structure2, in the Internet everywhere visible c/s architecture such as browser, online video, a variety of social software.The relationship between C/s architecture and socket:We learn sockets for the d
Python socket programming example
This example describes the Python socket programming in detail. Share it with you for your reference. The details are as follows:
Copy the Code as follows:
Sock =
that a socket can appear in multiple lists. The call select is blocked, but you can give it a time-out.Returns a list of 3. Contains readable, writable, and erroneous sockets.If a socket is in a readable list, then the call recv must return something to it. The same is true for writable. You can then use the read-write method used in the blocking operation above.
Create a server
is always listening for client requests to arrive ...
When a client connection arrives at the server
Executes the Threadingmixin.process_request method, creating a "thread" to handle the request
Execute the Threadingmixin.process_request_thread method
Executes the Baseserver.finish_request method and executes self. Requesthandlerclass () is the construction method that executes the custom Myrequesthandler (automatically calls the constructor of the base class Baserequesthandler,
sockets1 . Socket family based on file type Socket family name: Af_unixUnix all files, file-based sockets are called by the underlying file system to fetch data, two sockets process running on the same machine, you can access the same file system to complete the communication indirectly2 . Socket family based on network type
= self.request addr = Self . client_address # above two lines of code, equal to CONN,ADDR = Socket.accept (), but in the Socketserver module has been packaged for us, but also for our packaging including bind (), listen (), a Ccept () method while 1:accept_data = str (CONN.RECV (1024x768), encoding= "UTF8") print (ACCE Pt_data) If Accept_data = = "Byebye": Break send_data = bytes (Input ("> Gt;>>> "), encoding=" UTF8 ") Conn.sendall (Send_data) conn.close () if __name__ = = ' __main__ ': Sever
Af_inet is the most widely used one in all address families, Python supports a variety of address families, but since we only care about network programming, most of the time I use af_inet only)Six, Socket workflowA scene in the life. You have to call a friend, dial first, a friend hears a phone call, and then you and your friend establish a connection, you can
TCP/UDP standard.Third, TCP-based socketClassification of sockets:Socket family based on file type: Af_unix (on UNIX systems, everything is file, file-based sockets call the underlying filesystem to fetch data, two socket processes run on the same machine at the same time, can communicate indirectly by accessing the same file system)Socket family based on network type: af_inet (
Network Programming in Pythonfirst, socket () ModuleSecond, create a TCP serverThird, create a TCP clientFirst,socket moduleSocket:Sockets are originally created for applications on the same host, allowing a program (aka one process) running on the host to communicate with another running program. This is called interprocess communication (Inter processcommunicat
connected, Then go to the socket in the listen state to find */return SK? : __inet_lookup_listener (NET, Hashinfo, daddr, Hnum, dif);} Summarize the process: Server side After calling listen, the kernel establishes two queues, the SYN queue, and the accept queue, where the length of the accept queue is specified by the backlog. After the server has called accept, it blocks, waits for an element of the accept queue, and after the client calls connect
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.