python-Network Programming

Source: Internet
Author: User

1. Simple Socket Communication1.1. Service Side
Import socket# buy mobile phone = Socket.socket (socket.af_inet, socket. SOCK_STREAM) # Card Phone.bind ((' 127.0.0.1 ', 8080) # boot Phone.listen (5) # Wait for the phone link print (' Server start ... ') conn, client_addr = Phone.accept ()  # (TCP link, client_addr) print (' Link: ', conn) print (CLIENT_ADDR) # based on established links, send and receive messages Client_data = CONN.RECV ( 1024x768) print (' Client message ', Client_data) Conn.send (Client_data.upper ()) # Hang up the phone link conn.close () # Shutdown phone.close ()
1.2, the client
Import Socketphone = Socket.socket (socket.af_inet, socket. Sock_stream) Phone.connect ((' 127.0.0.1 ', 8080)) phone.send (' Hello '. Encode (' Utf-8 ')) Server_data = PHONE.RECV (1024) Print (' Message of service-side response ', Server_data) phone.close ()

  

python-Network Programming

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.