Add a condition to get out of the receive loop

Now can get out of the loop when receive "\n" or "\r" or "\r\n".
Add memory allocation

Now can use strcat() correctly. It's more safe than before.