Fixed TCP functionality (thanks, Pierre). Luckily it was not as broken as I imagined.