Stop socket.connect after some time #11947
-
Hi, I'm trying to program a local network IP scanner in an esp32 board. The purpose of this code is to find which IPs in a local network have port 502 open. For that, I'm using usocket library:
Problem: As I want to scan a lot of IPs, to speed up the process I would like to find a way to stop executing socket.connect after 0.5-1 seconds. Things that I tried:
As I understand, my problem isn't a specific problem with socket module. It is more a programming problem for stopping a function after some time if it doesn't end. I can solve it in "normal" Python, but not in Micropython. If necessary, I can attach the code. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
It might be a good idea to study the fine documentation, set the socket to nonblocking and use |
Beta Was this translation helpful? Give feedback.
-
Hey, there is an example in the linked doc - see the Something similar should work (can't test this in the moment):
Edit: |
Beta Was this translation helpful? Give feedback.
-
Hi, I tried this:
The last one, I imagine that it's because s.connect doesn't return anything |
Beta Was this translation helpful? Give feedback.
-
Thankss @karfas It works perfectly! I don't know what I was doing wrong when I test what you told me. I was so stuck in this issue. Great help! |
Beta Was this translation helpful? Give feedback.
Don't see a problem here.
Tried with