[tkined] UDP bind problem

From: Irina Brubaker (irinab@gnp.com)
Date: Tue Jun 20 2000 - 19:54:21 MET DST


Hi all,
        I am using scotty2.1.10 tnm package to send and receive udp datagrams.
        When I had a simple program without udp bind, it worked just fine.
Though if the server of the udp socket was dead, the program on the
client blocked on the udp receive forever. I thought I would try the
'udp bind $f readable [script]'. I am hoping to be able to return from
the function if nothing is readable (if the server is dead).
        Below is the code which does not work. I know it sends correctly, but
does not receive back anything.
        Please let me know what I am doing wrong.

Thank you,
Irina.
-------------------------------------
#!/bin/sh
# the next line restarts using scotty -*- tcl -*- \
exec scotty2.1.10 "$0" "$@"

package require Tnm 2.1

proc send { f ip cmd } {
    udp send $f $cmd
}

proc recv { f } {
    # get packet
    if {catch {set packet [udp receive $f] } err } {
        udp close $f
        puts "Error while receiving: $err"
        return
    }
    # parse the packet
    set addr [lindex $packet 0]
    set port [lindex $packet 1]
    set data [lindex $packet 2]

    # extract data
    puts $data
}

##
## Some command line parsing stuff.
##

set newargv ""
set parsing_options 1
while {([llength $argv] > 0) && $parsing_options} {
    set arg [lindex $argv 0]
    set argv [lrange $argv 1 end]
    if {[string index $arg 0] == "-"} {
        switch -- $arg {
            "-c" { set cmd [lindex $argv 0]
                   set argv [lrange $argv 1 end]
                 }
            "--" { set parsing_options 0 }
        }
    } else {
        set parsing_options 0
        lappend newargv $arg
    }
}

set argv [concat $newargv $argv]
if {$argv == ""} {
    puts stderr {usage: udpsendargs -c cmd hosts}
} else {
    foreach host $argv {
        set u [udp connect $host 4444]
        udp bind $u readable "recv $u"
        puts "Binded 4444"

        send $u $host $cmd
        puts "Sent the command"

        after 10000
        udp close $u
    }
}

--
!! This message is brought to you via the `tkined & scotty' mailing list.
!! Please do not reply to this message to unsubscribe. To subscribe or
!! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>.
!! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.



This archive was generated by hypermail 2b29 : Mon Jan 08 2001 - 15:27:47 MET