source: trunk/gui/filexfer/middleman.tcl @ 154

Last change on this file since 154 was 50, checked in by mmc, 19 years ago

Added support for file transfer with the desktop. Each Rappture
application acts like an http server, configured to listen on
a particular port according to the parameters found in the file
~/data/sessions/$SESSION/resources. When the server is active,
the GUI has a "Download..." button in the results area. A Java
client (in the filexfer directory) connects to the server and
listens for download requests. When the user clicks on "Download...",
the desired result is spooled to a file, and a Java client pops up
a web page requesting the file. This downloads the result to the
user's desktop.

Note that if the $SESSION environment variable is not set, these
changes do nothing.

File size: 1.3 KB
Line 
1#
2# Use this to test the HTTP protocol.  Start this server,
3# then treat localhost:9001 as a web site, and watch the
4# traffic between the client and the web server at localhost:80
5#
6set port 80
7if {[llength $argv] > 0} {
8    set port [lindex $argv 0]
9}
10
11set client ""
12set server ""
13
14proc accept {cid addr port} {
15    global client
16    fileevent $cid readable [list client_handler $cid]
17    fconfigure $cid -buffering line
18    set client $cid
19}
20
21proc client_handler {cid} {
22    global client server port
23    if {[gets $cid line] < 0} {
24        close $cid
25        set client ""
26    } else {
27        if {$server == ""} {
28            set server [socket localhost $port]
29            fileevent $server readable [list server_handler $server]
30            fconfigure $server -buffering line
31        }
32        puts "CLIENT: $line"
33        puts $server $line
34        flush $server
35    }
36}
37
38proc server_handler {sid} {
39    global client server
40    if {[gets $sid line] < 0} {
41        close $sid
42        set server ""
43    } else {
44        if {[regexp {[\000-\006\016-\037\177-\400]} $line]} {
45            puts "SERVER: --[string length $line] bytes--"
46        } else {
47            puts "SERVER: $line"
48        }
49        catch {puts $client $line}
50        catch {flush $client}
51    }
52}
53
54socket -server accept 9001
55vwait forever
Note: See TracBrowser for help on using the repository browser.