I am aware of disadvantages of "wait->stop" design, that usually is proposed with netcat:
server$ cat test.dat | nc -q 10 -l -p 7878
client$ nc -w 10 remotehost 7878 > out.dat
(It's not reliable : no meter how long you wait it's always possible that there was network bottleneck for one second longer. - Another thing -> why wait 10second if you can know immediately that data are transferred and start processing them !)
I'd like solution, with reliable and nice tcp stream closing.
I've found socat, with closing as described in man socat
:
When one of the streams effectively reaches EOF, the closing phase begins. Socat transfers the EOF condition to the other stream, i.e. tries to shutdown only its write stream, giving it a chance to terminate gracefully.
I found following commands working:
Server sending file:
server$ socat -u FILE:test.dat TCP-LISTEN:9876,reuseaddr
client$ socat -u TCP:127.0.0.1:9876 OPEN:out.dat,creat
Server receiving file:
server$ socat -u TCP-LISTEN:9876,reuseaddr OPEN:out.txt,creat && cat out.txt
client$ socat -u FILE:test.txt TCP:127.0.0.1:9876
Is it reliable? Can it be improved? (Have I used right options? Are there better options to setup? - There are so many of them with socat)