Python Learning Path: A simple example of a socket

Source: Internet
Author: User

Client

1 #Client2 ImportSocket3 4Client = Socket.socket ()#equivalent to declaring the socket type, while generating the socket connection object5Client.connect (('localhost', 6969))6 7Client.send (b"Hello world!")8data = CLIENT.RECV (1024)9 Print("recv:", data)Ten  OneClient.close ()
View Code

Service side

1 #Server-Side2 ImportSocket3 4Server =Socket.socket ()5Server.bind (("localhost", 6969))#bind the port to listen on6Server.listen ()#Monitor7 8 Print("I'm going to start waiting for the phone.")9 TenCONN,ADDR = Server.accept ()#wait for the phone to call in One Print(CONN,ADDR) A  - Print("here's the phone.") -  thedata = CONN.RECV (1024) - Print("recv:", data) - Conn.send (Data.upper ()) -  +Server.close ()
View Code

Python Learning Path: A simple example of a socket

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.