Version 2 of automatically generating socket based Tcl / C connection code, 1

Updated 2004-03-07 13:29:43

started by Theo Verelst

To make use a pipe or as here a general socket 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 [L1 ].

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.

Major issues when making a socket link and programming code around it are:

  • newlines
  • end of line
  • end of message
  • flow control
  • process issues
  • connection control
  • error correction/sensitivity

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.

Motivations and subsequent work include:

  • real time sound synthesis/analysis C code I have can be runtime tcl/tk controlled [L2 ]

[L3 ] [L4 ]

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