
Now if the client ever receives an EOF then it will wait for 5 seconds before terminating. This flag expects a number which depicts number of seconds to wait before client terminates (after receiving EOF)Ĭlient should be started like : nc -q 5 localhost 2389 In a normal scenario, if the nc client receives an EOF character then it terminates immediately but this behavior can also be controlled if the -q flag is used. Netcat client can be configured to stay up after EOF is received.

Configure Netcat Client to Stay Up after EOF So we see that by using the -k option the server remains up even if the client got disconnected. This behavior can be controlled by using the -k flag at the server side to force the server to stay up even after the client has disconnected. So, in the above example we see that as soon as the client got disconnected the server was also terminated. If the netcat client is connected to the server and then after sometime the client is disconnected then normally netcat server also terminates. The text ‘Hi’ will not be sent to the server end as using -d option the read from stdin has been disabled. In the following example, we used this flag at the client side. This functionality can be achieved by using the flag -d. So now a postfix ‘6’ with ‘tcp’ shows that nc is now using IPV6 addresses. Tcp6 0 0 localhost:33234 localhost:2389 ESTABLISHED Tcp6 0 0 localhost:2389 localhost:33234 ESTABLISHED Now, If we force nc to use IPV6 addresses Since in this case it is not, so a connection between server and client is established using IPV4 addresses. The first field in the above output would contain a postfix ‘6’ in case the IPV6 addresses are being used. Tcp 0 0 localhost:50851 localhost:2389 ESTABLISHED Tcp 0 0 localhost:2389 localhost:50851 ESTABLISHED Now, if we run the netstat command, we see : $ netstat | grep 2389

4 forces nc to use IPV4 address while -6 forces nc to use IPV6 address. The flag -4 or -6 specifies that netcat utility should use which type of addresses. NOTE : Do not use the -w flag with -l flag at the server side as in that case -w flag causes no effect and hence the connection remains open forever. The connection above would be terminated after 10 seconds. So after the seconds specified along with -w flag, the connection between the client and server is terminated.

In that case, through ‘-w’ switch we can specify the timeout in a connection. There are cases when we do not want a connection to remain open forever. So we see that the file data was transfered from client to server. Now, when we see the ‘test’ file at the server end, we see : $ cat test Now, we run the server as : $ nc -l 2389 > testĪnd run the client as : cat testfile | nc localhost 2389 At the client side, suppose we have a file named ‘testfile’ containing : $ cat testfileĪnd at the server side we have an empty file ‘test’ The netcat utility can also be used to transfer files. So we see that netcat utility can be used in the client server socket communication.
