Using threads to implement the socket service side to respond to multiple clients simultaneously

Source: Internet
Author: User

1 #using threads to implement server-side response to multiple clients simultaneously2 #! -*-Conding:utf-8-*-3 ImportSocket4 ImportThreading5 Import Time6Addr= ("127.0.0.1", 8808)7conn=Socket.socket ()8 Conn.connect ((addr))9 defPro (AA):Tendata = CONN.RECV (1024) One     Print(Str (data, encoding="Utf-8")) A  -Conn.sendall (bytes (AA, encoding="Utf-8")) -  while1: theAA = input ("Please enter \ n") -     - Pro (AA) - conn.close () +  -  + ImportSocket A ImportThreading at Import Time -Addr= ("127.0.0.1", 8808) -conn=Socket.socket () - Conn.bind ((addr)) -Conn.listen (5) - defClient (CONN1): inConn1.send (Bytes ("welcom to Server", encoding="Utf-8")) -      while1: toDATA=CONN1.RECV (1024) +         #if not data: -         # Break theConn1.sendall (Data+bytes ("Server Received", encoding="Utf-8")) *         Print("OK") $ conn1.close ()Panax Notoginseng  -  whileTrue: theSock,ar=conn.accept () +     Print(AR) AA=threading. Thread (target=client,args=(sock,)) the A.start () +     #A.join () -     Print("Biaoji")

Using threads to implement the socket service side to respond to multiple clients simultaneously

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.