This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Piped sockets under tcl

Help for those learning Tcl or writing their own scripts.
Post Reply
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Piped sockets under tcl

Post by Ofloo »

How do I create a named pipe instead of creating a socket to listen on. I've been searching google, looking through the manual, but I can't find anything about named pipes.
XplaiN but think of me as stupid
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Read about pipelines in the manpage for open:
http://www.tcl.tk/man/tcl8.4/TclCmd/open.htm
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

As far as I know is what you're suggesting only for execution.

Code: Select all

open "|/path/to/binary" r+
not to make named pipes (sockets)

such as /tmp/mysql.sock, for example, or would you be so kind explain yourself, ..
XplaiN but think of me as stupid
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Been a while since I played around with named pipes, but as I recall you create them with 'mknod' or 'mkfifo' and then just use them as regular files:

Example using two concurrent shell-sessions:
Session 1

Code: Select all

bash$ mknod /home/myhome/test.fifo
bash$ ls -l > /home/myhome/test.fifo
Session 2

Code: Select all

bash$ cat /home/myhome/test.fifo
-rwxr--r--   1 nml375 nml375    16896 26 maj  2006 network.doc
-rw-rw-r--   1 nml375 nml375     1927 11 okt  2005 private-root-pem.crt
...
Should'nt be much different with tcl..

Or where you thinking of unix sockets?
NML_375
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

i was thinking of making a script listen on a unix socket.
like:

Code: Select all

socket -server myproc localhost 1234
XplaiN but think of me as stupid
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

As far as I know, there is no support for unix sockets in tcl.
Also, keep in mind that "named pipes" is something completely different from "unix sockets", where the first one uses simple file I/O for communications while the second makes use of the kernels support for socket communication, with the domain AF_UNIX rather than AF_INET (which is used for IP sockets).

I suppose IP sockets won't cut it for you?

If you really want unix sockets, you'd have to create some wrapping-code to provide the function calls from the socket-library to the tcl-environment (possibly by creating an eggdrop module).
One option, I guess, would be to write your project entirely as a module rather than a tcl-script.
NML_375
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Perhaps user's code would help: socket api - nonblocking tcp made easy.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

I know how to use sockets, it's just that i want a to create a unix socket.

ok it's

Code: Select all

socket -server myproc -myaddr 127.0.0.1 1234
So I assume it's not possible.

i think maybe mknod might do..
XplaiN but think of me as stupid
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Keep in mind that named pipes are "one-way connections", that is, one client must open the fifo in readonly mode, and other client in writeonly mode.

Btw, if you wanted to work with unix socket, why were you asking for named pipes?
NML_375
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

I asked for a named pipe which functioned as a socket, UNIX sockets I suppose.

i want to be able to '|' pipe data from syslogd to a script.

but since reading from stdin is having some issues.. i wanted to use pipes instead.
XplaiN but think of me as stupid
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Pipes and sockets (IP/IPX/Unix/etc all alike) are two completely different concepts, hence there is no "named pipe with socket functions" (unix or otherwize).
Pipes are used just like any other file-stream, whereas sockets have a far more complex structure.

As for your intent to send data from syslogd; a quick check in the manual page would reveal that syslogd allows files, ip/udp, and named pipes to be destination for logmessages. It does not, however, support unix sockets as destination.
NML_375
Post Reply