sending data from Socket to a listbox
- From: "blaven@xxxxxxxxx" <blaven@xxxxxxxxx>
- Date: 17 Jul 2006 10:01:00 -0700
Hello:
I'm currently connecting to a server and want any data that is sent
to the client to be put in a listbox. My problem is that when data is
sent and my fileevent handler gets the data, my listbox (the whole UI
in fact) locks up. The event handler appears to continue to work and
print out anything it receives to stdout, but my listbox never gets any
entries. I'm sure it probably has something to do with the eventloop
not running or i'm blocking somehow. I'm just too new.. :( Here's my
code (I'm using some code I found on the mailing list to create my
socket):
#!/usr/bin/wish
set connectState 0
proc clientSocket {host port timeout} {
global connectState
#
# Create a client socket and connect
# it to the server asynchronously
#
set channel [socket -async $host $port]
#
# Schedule a command for execution timeout milliseconds later
#
set afterId [after $timeout {set connectState "timeout"}]
#
# Create a file event handler to be called when the
# connection attempt is either completed or fails
#
fileevent $channel writable "getErrorStatus $channel $afterId"
#
# Wait until the previously scheduled delayed command or
# the file event handler sets the variable connectState
#
vwait connectState
if {[string compare $connectState ""] == 0} {
return $channel
} else {
close $channel
return -code error $connectState
}
}
proc getErrorStatus {channel afterId} {
#
# Assign the current error status of the socket (an
# error message or an empty string) to connectState
#
global connectState
set connectState [fconfigure $channel -error]
#
# Cancel the execution of the peviously scheduled
# delayed command and delete the file event handler
#
after cancel $afterId
fileevent $channel writable ""
}
proc read_sock {sock} {
set l [gets $sock]
puts stdout "$l"
.lb insert end "HELLO"
}
listbox .lb
pack .lb
button .b1 -text blah -command {.lb insert end "HELLOB"}
pack .b1
set mySock [clientSocket "localhost" 9000 1000]
fconfigure $mySock -buffering line
puts $mySock
fileevent $mySock readable [list read_sock $mySock]
#####END
I would like it to insert HELLO everytime i get something on the socket
(or $I eventually). Thanks!
.
- Prev by Date: Re: Nasty problem with background fcopy from socket to stdout
- Next by Date: Re: Windows screen saver and toplevel -use option
- Previous by thread: GeoIP TCL extension.
- Next by thread: ANNOUNCE: Windows Inspection Tool Set (WiTS) 1.0
- Index(es):