Python io multiplexing

Source: Internet
Author: User

            

Perform multi-user access with a for loop

SEVER

Import Socketsk1=socket.socket () Sk1.bind ((' 127.0.0.1 ', 888)) Sk1.listen () Import selectipt=[sk1,]while True:    r_  List, w_list, e_list = Select.select (IPT, [], IPT, 1)    print (' Listening SK object%s '% len (IPT))    print (r_list) for        SK in R_list:        If Sk==sk1:            # indicates that a new customer has come            con,addr=sk.accept ()            ipt.append (con)        else:            # old customers send messages            Try:                data_bytes=sk.recv (1024x768)                data_str=str (data_bytes,encoding= ' utf-8 ')                sk.sendall (bytes (data_ str+ ' Hao ', encoding= ' Utf-8 '))            except Connectionreseterror:                ipt.remove (SK)

Python io multiplexing

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.