TCP and UDP

In case you do not have telnet or netcat handy to open a TCP or UDP client connection:

function send() {
    echo -e "$1" 1>&3
}

function receive() {
    read -u 3 0<&3
}

function openUDP() {
    (
        eval $3
    ) 3<> /dev/udp/$1/$2
}

function openTCP() {
    (
        eval $3
    ) 3<> /dev/tcp/$1/$2
}

function worker() {
    send "hallo"
    echo "got: $(receive)"
}

openTCP 10.1.1.1 8000 worker
Feedback is always welcome! If you'd like to get in touch with me concerning the contents of this article, please use Twitter.