in reply to handle tcp packets

Have you looked at Net::TCP;;Server or any of its relatives?