That is an astute observation. In fact I tried that, but the said 'right piece of code' works correctly only with one connection, when I hand that same code the socket connection from the multi connection version, it doesn't work correctly.
I think I will have to use an F5 appliance to do this unfortunately.
Thanks