Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all, I'm trying to do some experiments with net cat, i want to send a file via for several times and I want to measure throughput. The problem is ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2013
    Posts
    11

    checking whether server is listening or not with netcat


    Hi all,

    I'm trying to do some experiments with net cat, i want to send a file via for several times and I want to measure throughput. The problem is that each time Client and server are connected and sending is done, the connection is closed and I server should listen again. Consider following commands:

    Code:
    [root vm1]# nc -l 12345 > /dev/null
    and

    Code:
    [root vm2 ~]# dd if=/dev/zero bs=2000 count=500 | nc -v 192.168.122.193 12345
    each time I should run the command
    Code:
    [root vm1]# nc -l 12345 > /dev/null
    again, I cannot put this command in a loop. I tried it and I got :
    Code:
    nc -l 12345 > /dev/null
    nc: getaddrinfo: Servname not supported for ai_socktype
    nc -l 12345 > /dev/null
    nc: getaddrinfo: Servname not supported for ai_socktype
    nc -l 12345 > /dev/null
    .........
    How can I automate this?

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,755
    The -l port option turns nc into a server, so you should not need to restart it (which is why you are getting errors in the last examples of your post) unless you give it a timeout option and the timeout expires. IE, start nc -l port and then on the other host you can do the dd | nc as often as you want, though bear in mind that nc will handle multiple connections at the same time, so if one is not finished sending, and you start another, your timing results will be skewed.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Feb 2013
    Posts
    11
    That is not my case, server stop after first onnection for e.g second time I got this error in the client:
    Code:
    nc: connect to 192.168.122.193 port 12345 (tcp) failed: Connection refused

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,755
    This (from the nc man page) may help:
    Code:
         -k      Forces nc to stay listening for another connection after its current connection is completed.  It is an
                 error to use this option without the -l option.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #5
    Just Joined!
    Join Date
    Feb 2013
    Posts
    11
    Thanks a lot for your help. It worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •