SSAnderson
Programmer
I am having trouble getting my code to work. The GUI comes up but the fields are not updating. I think I am having a namespace issue. When the GUI comes up I telnet to 127.0.0.1 on the specified port and it logs in ok. When I type a command such as setColor yellow the GUI is not updated.
Code Here:
#!/usr/bin/wish
set parser [interp create -safe]
$parser eval {
proc setStatus {lbl} {
global statusValue
set statusValue $lbl
return $lbl
}
proc setColor {clr} {
global colorCanvas
$colorCanvas configure -bg $clr
return $clr
}
}
proc acceptConnect {cid addr port} {
fileevent $cid readable [list serverHandle $cid]
fconfigure $cid -buffering line
}
proc serverHandle {cid} {
global parser
if {[gets $cid request] < 0} {
close $cid
} else {
if {[catch {$parser eval $request} result] == 0} {
puts $cid $result
} else {
puts $cid [list error_result $result]
}
}
}
proc MakeGUI {} {
global colorCanvas
frame .ttl -relief raised -bd 2
label .ttl.lbl -text {Socket Parser Demo}
pack .ttl.lbl -side top -fill x -padx 40 -pady 10
pack .ttl -side top -fill x
set statusValue {(none)}
frame .wdgts -relief raised -bd 2
label .wdgts.slbl -text { status value:} -anchor e -width 20
entry .wdgts.ent -textvariable statusValue
grid .wdgts.slbl .wdgts.ent -sticky w
label .wdgts.clbl -text { Color Value:} -anchor e -width 20
set colorCanvas [canvas .wdgts.cvs -bg green -width 80 -height 16 -relief sunken -bd 2]
grid .wdgts.clbl .wdgts.cvs -sticky w
pack .wdgts -side top -fill x
button .xit -text {Dismiss} -command {exit}
pack .xit -side top -fill x
}
#Make the graphical user interface
MakeGUI
socket -server acceptConnect 9001
Code Here:
#!/usr/bin/wish
set parser [interp create -safe]
$parser eval {
proc setStatus {lbl} {
global statusValue
set statusValue $lbl
return $lbl
}
proc setColor {clr} {
global colorCanvas
$colorCanvas configure -bg $clr
return $clr
}
}
proc acceptConnect {cid addr port} {
fileevent $cid readable [list serverHandle $cid]
fconfigure $cid -buffering line
}
proc serverHandle {cid} {
global parser
if {[gets $cid request] < 0} {
close $cid
} else {
if {[catch {$parser eval $request} result] == 0} {
puts $cid $result
} else {
puts $cid [list error_result $result]
}
}
}
proc MakeGUI {} {
global colorCanvas
frame .ttl -relief raised -bd 2
label .ttl.lbl -text {Socket Parser Demo}
pack .ttl.lbl -side top -fill x -padx 40 -pady 10
pack .ttl -side top -fill x
set statusValue {(none)}
frame .wdgts -relief raised -bd 2
label .wdgts.slbl -text { status value:} -anchor e -width 20
entry .wdgts.ent -textvariable statusValue
grid .wdgts.slbl .wdgts.ent -sticky w
label .wdgts.clbl -text { Color Value:} -anchor e -width 20
set colorCanvas [canvas .wdgts.cvs -bg green -width 80 -height 16 -relief sunken -bd 2]
grid .wdgts.clbl .wdgts.cvs -sticky w
pack .wdgts -side top -fill x
button .xit -text {Dismiss} -command {exit}
pack .xit -side top -fill x
}
#Make the graphical user interface
MakeGUI
socket -server acceptConnect 9001