Im new in Python. And I can't make the server listen to two ports at the same time. This is the code I have written until now:
sock_client1 = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock_client1.bind((SEND_IP, SEND_CLIENT_PORT))
sock_client1.setblocking(0)
sock_client2 = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock_client2.bind((SEND_IP, SEND_SERVER_PORT))
sock_client2.setblocking(0)
while True:
try:
ready_client1 = select.select([sock_client1], [], [], None)
ready_client2 = select.select([sock_client2], [], [], None)
if ready_client1[0]:
pkt_recv_raw, addr = sock_client1.recvfrom(4096)
port = SEND_CLIENT_PORT
if ready_client2[0]:
pkt_recv_raw, addr = sock_client2.recvfrom(4096)
port = SEND_SERVER_PORT
When I run this code together with a client, the server can't receive anything. It just works when I use only one of the ready_client's.
Thanks in advance!