i think the following sample can be some help
:)
#!/bin/sh
# the below lines execute with tclsh \
exec tclsh "$0" "$@";
set x [socket -myaddr 172.20.1.227 172.20.1.227 8100];
set f [open /root/data r];
fconfigure $x -blocking 0 -buffering line -eofchar \0;
proc Read {x} {
global done;
set line [read $x];
regsub -all {\x1C} $line + str;
puts "recv> $str";
set done 1;
}
proc send {in out} {
gets $in com;
puts "send> $com";
if {![string equal $com quit]} {
regsub -all {\+} $com \x1C str;
puts -nonewline $out $str;
flush $out;
return 0;
} else {
close $out;
return 1;
}
}
fileevent $x readable [list Read $x];
set count 1;
while {1} {
if {![eof $f]} {
send $f $x;
} else {
# puts "close";
close $f;
break;
}
after 70;
puts [incr count];
vwait done;
}
while {1} {
gets stdin com;
puts "send> $com";
if {![string equal $com quit]} {
regsub -all {\+} $com \x1C str;
puts -nonewline $x $str;
flush $x;
} else {
close $x;
}
after 1000 [list set done 2];
vwait done;
}
"anuj" <anuj_mistry@spanservices.com> ????
news:1140089144.868390.305880@o13g2000cwo.googlegroups.com...
> Hello All,
>
> I am facing a problem with fileevent handling. My code looks something
> like this:
>
> readUDP {socket} {
> :
> # read the incoming message, use it to build the reply message and
> send it back to the
> # other end
> :
> }
>
> openSock {} {
> :
> :
> fileevent $sock readable [readUDP $sock]
> :
> :
> }
>
> When the fileevent triggers, the readUDP proc gets called, wherein I am
> preparing a reply message. In the meantime, there is another message
> coming in from the other end and the fileevent gets triggered. As a
> result, readUDP gets called even before I complete building the reply
> message.
>
> How should I make sure that I complete the processing (build and send
> reply) before entertaining the next incoming message?
>
> Thanks in advance :)
>
> Regards,
> Anuj.
>
Received on Sun Apr 30 02:07:37 2006