Maybe I don't know enough about Lua, but the structure of your functionality doesn't appear to be standard. See the NodeMCU firmware wiki for creating a server and listening to ports.
UDP also makes no transmission guarantees. It's possible TCP only works because under the hood your TCP stack is resending packets like crazy until one finally gets through.
I know you can't have two different TCP servers running at once... I wonder if starting up the first TCP server is interrupting or shutting down the UDP server?
Have you tried scaling the code back to just printing the message you received and running only that on the esp, and seeing how many packets get through without all the rest of the variables?