In bash you can fork process with & control operator and get the pid of child reading $!. So, the simplest solution could be
$ ( nc -l 1234 & echo $! > /tmp/myprog_kill_pid ) | myprog; kill $(</tmp/myprog_kill_pid); rm /tmp/myprog_kill_pid
Of course, this is not very nice and not suitable for multiple running instances... but you can start from this.