5

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
  • 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
    Commented Jan 21, 2016 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
    Commented Jan 21, 2016 at 15:50

1 Answer 1

2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .