change tcpsocket into a thread