[RDY] fix TCP connection (issue #870)

This fixes the broken TCP connection. It does not change the functions used to copy the IP address. Maybe there are some more improvements to be made here as described in issue #870.
If this is happening, the ip addr will be invalid. Why still try to extract the ip address and the port? Are spaces allowed after the ip?