Line | |
---|
1 | # TCL Server for Azimuth Interaction |
---|
2 | # |
---|
3 | # Author: Siddharth Gupta |
---|
4 | |
---|
5 | package require Azimuth-Sdk ;# needed to include Azimuth package |
---|
6 | |
---|
7 | puts "Starting TCL server and listening on port 10102" |
---|
8 | |
---|
9 | proc Azimuth_Server {port} { |
---|
10 | set s [socket -server ConnectionAccept $port] |
---|
11 | vwait forever |
---|
12 | } |
---|
13 | |
---|
14 | |
---|
15 | proc ConnectionAccept {sock addr port} { |
---|
16 | global connectedClient |
---|
17 | puts "Accept $sock from $addr port $port" |
---|
18 | |
---|
19 | if [info exists connectedClient] { |
---|
20 | close $connectedClient |
---|
21 | puts "Closed $connectedClient" |
---|
22 | } |
---|
23 | |
---|
24 | set connectedClient $sock |
---|
25 | |
---|
26 | fconfigure $sock -buffering line |
---|
27 | |
---|
28 | fileevent $sock readable [list DataAccept $sock] |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | proc DataAccept {sock} { |
---|
33 | global connectedClient |
---|
34 | |
---|
35 | if {[eof $sock] || [catch {gets $sock line}]} { |
---|
36 | close $sock |
---|
37 | puts "Closed $connectedClient" |
---|
38 | unset connectedClient |
---|
39 | } else { |
---|
40 | set success 0 |
---|
41 | set reterr 0 |
---|
42 | puts "Executing '$line'" |
---|
43 | if {[catch {eval $line} err]} { |
---|
44 | set reterr $err |
---|
45 | } else { |
---|
46 | set success 1 |
---|
47 | } |
---|
48 | if {$success == 0} { |
---|
49 | puts $sock "ace_error: $reterr, command: $line" |
---|
50 | } else { |
---|
51 | puts $sock "ace_success: $line" |
---|
52 | } |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | Azimuth_Server 10102 |
---|
Note: See
TracBrowser
for help on using the repository browser.