[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to keep tcp connection open?
From: |
Koichi Murase |
Subject: |
Re: How to keep tcp connection open? |
Date: |
Mon, 13 May 2024 23:38:50 +0900 |
2024年5月13日(月) 23:28 Peng Yu <pengyu.ut@gmail.com>:
> If I just run the following command in an interactive session,
>
> read -N 4 var < /dev/tcp/127.0.0.1/2828
A redirection for a normal command is closed at the command's
termination. You need to open a file descriptor using `exec
<redirection>'.
$ exec {fd1}< /dev/tcp/127.0.0.1/2828
Then, you can read from the file descriptor using
$ read -N 4 -u "$fd1" var
or
$ read -N 4 var <&"$fd1"
You can continue to use the file descriptor.
> read -N "$((n-${#n}))" rest < /dev/tcp/127.0.0.1/2828
$ read -N "$((n-${#n}))" rest <&"$fd1"
However, it should be noted that if it takes time to input the next
command, the connection might be closed by the remote end for a
timeout.
After finishing the transaction, you can close the file descriptor by
$ exec {fd1}>&-
--
Koichi