basic nc question

i'm doing this in one terminal:

nc -lu 7402

and it appears to start listening properly, then in another i do this:

echo "hello" | nc -u localhost 7402

and nothing happens on the listening terminal - what am i doing wrong?

thanks.

Worked on my CentOS perfectly.


 nc -lu 7402
hello


# echo "hello" | nc -u localhost 7402

I would guess if its not working the port is blocked.

damn, must be this osx implementation of bash..

thanks for trying it.

Check for port blocking.

how i do i do that?

netstat will show you if some process has port nn open - ie., you cannot open it because it is blocked -

netstat | grep 'nodename\.23'

where 23 is the port you want to check

thanks for this.

sorry, 1 more question - when i do nc with the -u option, it keeps running and doesn't give me the next prompt until i press ctrl-c. is there a way to stop this from happening? even if i put it in a script with exit 0 at the end this doesnt help.

i've found that -w for a timout is one way to do it, but even 1 second makes it a bit unresponsive (for what i'm doing the script may need to run in quick succession)