4

How can I have a netcat connection terminate the sending half of a TCP connection if its input reaches EOF?

I have a (non-standard) TCP service which reads all its input (i.e. until the client sends its FIN), and only then starts processing the data and sending back a reply. I would like to use nc to interact with this service. But at the moment the reply doesn't arrive at the nc console, and using Wireshark I can see that nc only terminates the sending side of the connection when it quits (e.g. because of a timeout). I found no command line option to change this behavior.

  • 2
    you might try socat as it says in the write direction it will transfer the eof then wait -t<timeout> seconds on the read direction. – meuh Jan 21 '16 at 15:02
  • @meuh Thanks a lot! Even though I was asking about nc, it might well be that your comment is as much of an answer as I can get here. So I'd welcome seing that posted as such. – MvG Jan 21 '16 at 15:50
1

The comment by @meuh suggested using socat for this purpose. Based on that I've successfully used

some command | socat -t30 - TCP:localhost:1234

To transfer data including EOF and then still receive the response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.