Reconnecting to the server once loss of connection is detected

Hi,

I have made a TCP server/client script that reconnects to the server once loss of connection is detected. It’s working fine with the python interpreter but on uploading it on GHPython it freezes it and I have to force close grasshopper. How can I fix it?
Here I have attached the scriptTask 1 with emergency plan.py (1.1 KB)