Python Network Programming Chapter

Source: Internet
Author: User

   Basic Analog Call Network program:

1 #Client2 ImportSocket3 4Client =Socket.socket ()5Client.connect (('localhost', 6969))6Client.send (b"Hello ni hao")#only byte codes can be transferred in Python37data = CLIENT.RECV (1024)#1024 Specify the accepted data size to assign the accepted data to the value to data8 Print("recv:", data)9Client.close ()

1 ImportSocket2 3 #Service Side4Server =Socket.socket ()5Server.bind (('localhost', 6969))#bind to listen port6Server.listen ()#Monitor7 Print("I'm going to start waiting for the phone.")8CONN,ADDR = Server.accept ()#wait for the call. Accept returns a value of two conn,addr conn the linked instance client that was generated for the connection and the address of the other link that was created on the server side for the instance addr9 Print("here's the phone.")Tendata = CONN.RECV (1024)#accepts 1024 bytes and assigns the received data to the value One Print("recv:", data) AConn.send (Data.upper ())#returns the received data to the client after a capitalization operation -Server.close ()

Python Network Programming Chapter

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.