running script in background

hey guys,
I want to run a script in blender continuously in the background. the goal is to connect via tcp to another pc and send/receive data. I already tried the modal time operator and a little bit with threading. but it didnt worked good for me.
do you have any ideas how to realize it?

ty and greetz