This can be made very small if written in a compiled language such as C. There are many simple examples of how to do this; one of my favorites is Beej's Guide to Network Programming Bash is probably not the tool you want to use for this, especially in a resource-constrained environment.