added code for tcp loopback, almost done