Tracing back I see you read a string from a file and expect it to magically become a socket handle. That's not gonna happen.
In fact, the handle gets closed at the end of PortConn as the last reference to it ($rethandle) goes out of scope.
The idea is fundamentally flawed. A handle is a token that represents a resource the OS has handed your process. The token is useless to any other process. If you want to store something, you need to store the connection details so you can re-establish the connection.
Could you please point some good design options?
Also, will it work if I try to make it without threads using non-blocking socket call?
so if I try to connect to a port and it is not up then instead of blocking I just skip to next port without any delay. Is this something that makes more sense than previous approach?