use select() to listen on both tcp and udp message

后端 未结 1 818
予麋鹿
予麋鹿 2021-01-13 17:33

I only get the TCP message when I try this code:

from socket import *
from select import select

def read_tcp(s):
    while True:
        client,addr = s.acc         


        
相关标签:
1条回答
  • 2021-01-13 17:56
    1. Get rid of the 'while' loops in read_tcp() and read_udp(). The select() loop is the only loop you need: it will call the read_XXX() methods as often as required. The read_XXX() methods should handle exactly one event.

    2. Your read_tcp() method should be split into two parts: one to accept a socket and add it to the selection set, and another to read an accepted socket. Adjust the select loop accordingly.

    0 讨论(0)
提交回复
热议问题