The plugs do not close immediately

I have a script that opens a socket, reads some data and then closes and closes the socket.

If I put this script in a loop, I receive an error that tells me that the socket is still in use and I cannot create another socket on this particular port.

How do I force the closure of a socket to open the port to create a new socket?

(This is in Windows 10)