Convert UDP packet script to TCP packet

Hope someone can help me out here

Perhaps a description of what your code is intended to do will help.