Bash Shell Trying to use 'netcat' and 'mkfifio'? Or Whats the best way
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bash Shell Trying to use 'netcat' and 'mkfifio'? Or Whats the best way
Hi All,
I've set-up a netcat tcp connection from one computer to another... main reason is to find out if a connection is ever dropping as it appears to sometimes and this is causing some problems for some other software i run. Anyway... what i want to do is to have some kind of pipe straight into the netcat
The best way i've been able to do this so far is:-
mkfifo test123
tail -f test123 | netcat -l -p 1234
and then to just `echo blah > test123` in a while looped script
But is that the best way... i think probably not although it works.... i'm just being curious... i just don't like the tail -f i'm having to do whether thats the best way or not?
What i do currently is have a large file with a load of numbers.. equating to 3 days worth of constant connection. with netcat -i 60 -l -p 12345. What i'd prefer is (real time) `date` to be sent down the connection so if it does go i get an exact date when the last successful transmission was made.
Cheers All
MJ
Last edited by helptonewbie; 11-17-2008 at 07:02 AM.
Hi,
Thanks for the reply... two reasons i'm not using ping is that ... i'm already running it .. it doesn't detect any problems as yet but i know there might be, but to fast for ping to notice a problem and plenty enough of a problem that a connection is dropped.
And two, because its a constant connection i'm trying to imitate ping isn't as such a constant open connection with a stream of data its more of a 'ping' :-o hehe
TCP/IP is more robust than you give it credit for.
Test how tolerant it is by setting up the tests across your lan and then unplug an ethernet cable for a second or two. Keep increasing the unplug time until your "connection" is eventually broken.
With ping you'll see the round-trip times increase until the connection is eventually broken (ie packet errors) and you'll easily see when and for how the long the problem existed.
The packet network concept of a connection is not a good analogy to the physical world of water pipes or electrical connections. A packet network connection is a pair of programs listening and writing to sockets, with packets of data arriving sporadically and with "gaps" between each, the programs have no perception of how the packets got from A to B, how long it took or what happened on the way, they only receive an error if the TCP/IP layer fails to get a response within the time-out period.
Have a look at the output of "netstat -i", if you're seeing lots of TX and/or RX errors for the relevant interface then you know there's something wrong with your network.
Related to your original post, you can use cat instead of tail because cat will block while waiting for input from the pipe as long as the writing end is open. I'm actually surprised that tail works.
ta0kira
Thanks Guys, useful info. I know TCP is robust but it will tell me if the NIC has some kind of a small failure and drops any current connections, and that i will be able to see with a netcat, i could see it with a ping possibly as well. But i could also happen so fast that a ping won't pick-up on the problem. So anyway i'm using both already so i'm covered from all angles.
ta0kira - Thanks for the reply and yes it is working but i will change it to using cat, with your re-marks.. i think i did try before but the only thing i could get to work was tail -f..... but i'll give it another go anyway at some point.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.