to give you a rough idea what this can look like.
Note: this server is only thought to be for 1 client if you want to support multiple clients you will need something like tcpserver.
rm_file(){
 [ ! -e "${1}" ] || rm "${1}"
}
Cleanup() {
 for cjob in $(jobs -p) ;do
   kill -s SIGTERM "${cjob}"
 done
 rm_file /tmp/$$_srv_in
 rm_file /tmp/$$_srv_out
 rm_file /tmp/$$_clnt_in
 rm_file /tmp/$$_clnt_out
}
trap Cleanup EXIT
host=localhost
port=5667
case ${1} in
 Server)
   mkfifo /tmp/$$_srv_in || exit 1
   mkfifo /tmp/$$_srv_out || exit 1
   nc -l ${port} 0<>/tmp/$$_srv_out 1<>/tmp/$$_srv_in &
   while IFS=$'\v' read -ra cline; do Â
     : $((cnt++))
     printf "%q " "address@hidden" ; echo ;
     case ${cline[0]} in
       get_env)
         printf "%s\n" "${!cline[1]}" >/tmp/$$_srv_out
         ;;
       *)
         echo "${cnt}" >/tmp/$$_srv_out
         ;;
     esac
   done </tmp/$$_srv_in
   ;;
 Client_ver1)
   mkfifo /tmp/$$_clnt_in || exit 1
   mkfifo /tmp/$$_clnt_out || exit 1
   nc "${host}" ${port} 0<>/tmp/$$_clnt_out 1<>/tmp/$$_clnt_in &
   ask_server(){
       { printf '%s\v' "address@hidden" ; echo ; } >/tmp/$$_clnt_out
       IFS=$'\v' read -ra REPLY </tmp/$$_clnt_in
   }
   for ccmd in cmd1 cmd2 cmd3 ; do
     ask_server "${ccmd}"
     printf '%-15s : %q\n' "${ccmd}" "${REPLY}"
   done
   for ccmd in HOSTNAME USER ; do
     ask_server get_env "${ccmd}"
     printf '%-15s : %q\n' "${ccmd}" "${REPLY}"
   done
   ;;
 Client_ver2)
   exec 3<> /dev/tcp/${host}/${port} || exit
   ask_server(){
       { printf '%s\v' "address@hidden" ; echo ; } >&3
       IFS=$'\v' read -ra REPLY <&3
   }
   for ccmd in cmd1 cmd2 cmd3 ; do
     ask_server "${ccmd}"
     printf '%-15s : %q\n' "${ccmd}" "${REPLY[*]}"
   done
   exec 3>&-
    Â
   ;;
esac