Bugfixing TCP

Add a TCP test case
Fixes all the bug related to the TCP implementation.