started by Theo Verelst To make use a [pipe] or as here a general [socket] [http://mini.net/tcl/10283] [http://mini.net/tcl/9844] to connect a user interface with a progam or to link programs together is a long used and tried solution since at least X windows. Not that that always worked perfectly, but its pretty ok. Also web servers/browsers, [ftp], etc are examples of existing progams making use of socket IPC. The principle is clear enough: one makes a stream connection, and sends messages across with commands and data [http://mini.net/tcl/9102]. In practice, this doesn't work out all too easy, usually. This page presents an example to do most work completely automatically to make a tcl program connect with a C program, and have the C program execute functions under control of the tcl program (alternatively: [C compiled image processing on an interactive Bwise canvas]). Also, an example is easily created, where Tk is used to have a stack of buttons for testing this. On this page I used a recent windows XP running [KDE] (on an X simulator), and my own compiled tcl/tk 8.4 (but like on linux) in kde windows. Also, I used the [cygwin] unix-like environment including gcc compiler for windows. Most or all of the materials presented here should run equally well on linux/unix, and probably other os-es, provided they have a C compiler with unix flavour sockets. Major issues when making a socket link and programming code around it are: * newlines (one or two characters, newline or carriage return) * end of line (don't forhet '\0' to terminate C strings) * end of message (how do you know the whole message is in) * flow control (no dead/live lock, buffer sizes) * process issues (creation, referencing, security, joint load) * connection control (setup, re-setup, connection with protocol, leakless cleanup, eof issues) * error correction/sensitivity (incomplete messages,resyncing) The approach taken for this test version consists of the following steps: 1. define a list of message names, which are also used as corresponding C function names 2. make the socket connection possible both on C and Tcl side 3. generate automatically the C message handler and the frame of the C functions 4. generate Tcl/Tk code to make a button for each message 5. save and compile the generated C file 6. link it with the socket code 7. run the resulting C program 8. connect the tcl program 9. test the buttons to see if the corresponding C functions get called. [http://82.168.209.239/Wiki/cframecon.jpg] [http://82.168.209.239/Wiki/cframebut.jpg] [http://82.168.209.239/Wiki/cframett.jpg] [http://82.168.209.239/Wiki/cframecon.jpg] ---- Motivations and subsequent work include: * real time sound synthesis/analysis C code I have can be runtime tcl/tk controlled [http://members.tripod.com/%7Etheover/softsyn.html] [http://82.168.209.239/fosdem/] [http://82.168.209.239/Articles/pms.html] * idem for 3D graphics [http://mini.net/tcl/10449] * webserver extensions in c or tcl [Web pages with images] * BWise-ification of the various blocks here [http://mini.net/tcl/10291] * distributed applications (protocol based [http://mini.net/tcl/8733] [http://mini.net/tcl/8791]) [http://mini.net/tcl/11013] [distributed linked bwise] [http://mini.net/tcl/10135] ----