mkfifoを使用してNetcatサーバーとテキストパイプを接続する

mkfifoを使用してNetcatサーバーとテキストパイプを接続する

netcatサーバーがサーバーにテキストを入力するための2つのパイプと、サーバーからテキストを出力するための別のパイプを作成したいと思います。入出力パイプを持つ別のスクリプトでサーバーを実行しています。まだ作成していない別のスクリプトは、入力パイプを使用してnetcatサーバーの出力を読み取り、データを出力パイプに送信します。これが起こっている間、クライアントはサーバーにデータを送信していますが、私が作成していないスクリプトはクライアントから送信されたデータをサーバーから読み取り、サーバーに出力してクライアントに送信します。 。出力パイプまたは入力パイプを追加すると、サーバースクリプトはクライアントからデータを受け取らず、入力パイプに送信されたデータに応答しません。なぜこれが起こるのかわかりません。誰かがこれを行う方法を教えてくれたらいいでしょう。

サーバースクリプト:

#!/bin/bash

mkfifo in
mkfifo out

sudo nc -lk 22 <in >out
#Yes, I know I can run this in background, but I don't
#+want to do that yet.

クライアントスクリプト:

#!/bin/bash

while [ 1 ]
do
nc localhost 22
done
#I know this block looks odd, but it allows the client to continue
#+communicating with the server, even after an EOF.

理論的なサーバー処理スクリプト:

#!/bin/bash
#This script is run after the server script is run in another console.

while [ 1 ]
do
in="$(cat out)" #The script will be stuck here until there is output from the "out" pipe
if [ $in = "blah" ]
then
echo "blah to you, too." >in #Here, the echo output should be sent to the client from the server
fi
#I can add a lot more here after I get this sorted out
done

ベストアンサー1

おすすめ記事