Check out example codes for "exit telnet". It will help you in understanding the concepts better.

Code Example 1

#Ctrl+C doesn't work, you should ctrl+] but the most easy way
#is just type "quit" and enter
quit

Learn ReactJs, React Native from akashmittal.com