How to make nc
client on OS X Mavericks keep socket open and read data until server disconnects the socket?
I want to send data to a server through nc
and then use the response. Problem is that nc
disconnects the socket after the data has been sent, without waiting for the server's response.
This will just write the data then exit:
$ echo "my instruction here" | nc 127.0.0.1 $MY_PORT
This will write the data and then not exit even though the server has disconnected:
$ cat <(echo "my instruction here") - | nc 127.0.0.1 $MY_PORT
The nc
man page on OS X Mavericks have the following example for sending a HTTP GET
request and printing the response, but it's not working. It just sends the request then exits without waiting for the server's response. Seems like the man page's information is incorrect?
$ echo -n "GET / HTTP/1.0\r\n\r\n" | nc host.example.com 80