How to develop with Python client? Detailed Python modules with examples

Source: Internet
Author: User
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)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.