Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ksh - "cannot create" /dev/tcp/host/port

747 views
Skip to first unread message

danr

unread,
Apr 25, 2007, 11:14:19 AM4/25/07
to dric...@cisco.com
I'd like to familiarize myself with use of the ksh capability of
communicating machine-to-machine via a socket (a host/port pair). I've
read through the other postings on this topic, but I haven't seen
advice on how to get past the "cannot create" error. For example:

$ exec 3<> /dev/tcp/127.0.0.1/54321
./-ksh: /dev/tcp/127.0.0.1/54321: cannot create [Connection refused]

I came across an example on the web that does indeed work on my
machines (SunOS and Linux). It communicates with a specific machine
somewhere out there in the world.

host=rs.internic.net
port=43
exec 3<> /dev/tcp/$host/$port
set kornshell.com
print -u3 -f "%s\r\n" "$@"
cat <&3

However, when I use an IP address or hostname of one of my machines in
the above "exec ...", it always fails. For example, for for my
machine's "daytime" port (13) or my machine's dynamically-allocated
port "54321":

$ exec 3<> /dev/tcp/127.0.0.1/13
./-ksh: /dev/tcp/127.0.0.1/13: cannot create [Connection refused]

What I'm I missing?
Thanks,
Dan

bsh

unread,
May 7, 2007, 7:19:30 PM5/7/07
to

Yes indeed, the builtin networking of ksh88 and newer
would have been a wonderful facility, were it to have been
a _reliable_ feature, insofar as most kornshells I have used
have this facility unusable for one reason or another.

Instead of a long-winded discourse, I'll redirect you to another
thread that discusses this with more technical detail:

http://groups.google.com/group/comp.unix.shell/browse_thread/thread/9e636955554df9de/d783723076997023?lnk=st&q=&rnum=4#d783723076997023

Keep in mind that your problem could still be something not
related to ksh(1), but to another networking issue -- it's usually
an issue with dynamically-allocated ports, except that you
indicate that the well-known port 13 doesn't work.... With only
the above information, there is no way to determinately tell.
Start jiggling connectors? ;)

Try some other scripts:

"httpd.bash"
http://home.eol.ca/~parkw/httpd.sh

"sh-httpd.ash"
http://sourceforge.net/projects/sh-httpd/
(Try host: http://www.pugo.org:8080/)

"httpd.ksh"
http://shelldorado.com/newsletter/issues/1999-2-Sep.html

=Brian

0 new messages