Fixed TCP code to work

Lets try this again, i apologies for my lack of git knowledge last time.  This works with the current git release. And doesn't seam to have any bugs for me minimal changes from denhua's code.