Which module is best programmed in this article with the previous Python network? As an example of Python module, we introduce the service side and
python clientDevelopment, I hope to help you.
Client : Contact the server for a specific request, receive the service, and process the party for the related transaction. The client can continue to send requests to the server, or it can no longer make requests after the transaction request is ended.
Next we write a simple python client instance that connects to the service created above. The port number is 12345.
The Socket.connect (Hosname, Port) method opens a TCP connection to a service provider that hosts a port of hostname. After the connection we can get the data from the server and remember that the connection needs to be closed after the operation is completed.
The complete code is as follows:
#!/usr/bin/python#-*-coding:utf-8-*-# file name: Client.pyimport socket # import Socket Module s = socket.socket () # Create socket Object host = Socket.gethostname () # gets the local hostname port = 12345 # set Port good S.connect ((host, port)) print S.recv (1024x768) s.close ()
Now we open two terminals, the first terminal executes the server.py file:
$ python server.py
The second terminal executes the client.py file:
$ Python client.py Welcome to the PHP Chinese web!
When we open the first terminal again, we will see the following information output:
Connection address: (' 192.168.0.118 ', 62461)