LINUX.ORG.RU

История изменений

Исправление vodz, (текущая версия) :

Сервер:

#!/bin/bash

coproc nc -l localhost -p 4444

while read -r cmd; do
  case "$cmd" in
    d) date ;;
    q) kill "$COPROC_PID"
       exit ;;
    *) echo "What?" ;;
  esac
done <&${COPROC[0]} >&${COPROC[1]}
Клиент как скрипт:
#!/bin/bash
exec 42<>/dev/tcp/localhost/4444  # open bidirectional socket on fd 42
echo d >&42  # send message
cat <&42      # read response
echo q >&42  # send message
# close fd (both sides)
exec 42<&-    
exec 42>&-

Исходная версия vodz, :

Сервер:

#!/bin/bash

coproc nc -l localhost -p 4444

while read -r cmd; do
  case "$cmd" in
    d) date ;;
    q) kill "$COPROC_PID"
       exit ;;
    *) echo "What?" ;;
  esac
done <&${COPROC[0]} >&${COPROC[1]}
Клиент как скрипт:
#!/bin/bash
exec 42<>/dev/tcp/localhost/4444  # open bidirectional socket on fd 42
echo date >&42  # send message
cat <&42      # read response
echo q >&42  # send message
cat <&42      # read response
# close fd (both sides)
exec 42<&-    
exec 42>&-