我开始学习 tcl 脚本语言,我正在尝试做一个 tcl 脚本,它通过单播网络隧道传输所有多播数据包。
由于我是tcl的新手,所以我想问点:
我正在使用 Eclipse 在 tcl 中进行编码,我已经安装了所需的插件,并且我认为还有所有的包,但是,Eclipse 强调了我下面的调用
fconfigure $sockMulticast -buffering none -mcastadd $ipMulticast -translation binary -remote [list $ipMulticast $port]
说有额外的论点,我不明白,因为在这里可以阅读:
Pat 写道:“多播与标准单播或广播 UDP 略有不同。您的操作系统会忽略多播数据包,除非应用程序已明确加入多播组。在 TclUDP 的情况下,我们通过使用
fconfigure $socket -mcastadd $mcastaddress
当我配置 TCP 套接字(单播)时,我应该在调用时再次指定目标单播 IP
fconfigure
吗?
代码:
#!/bin/sh
# updToTcp.tcl \
exec tclsh "$0" ${1+"$@"}
package require udp
set ::connectionsMulticast [list]
set ::connectionsUnicast [list]
proc udp_connect {ipMulticast ipUnicast port {multicast false}} {
#Open UDP multicast socket
set sockMulticast [udp_open $port]
if {$multicast} {
#configures the multicast port
fconfigure $sockMulticast -buffering none -mcastadd $ipMulticast -translation binary -remote [list $ipMulticast $port] ;#(1)
#update the list of multicast connections with the socket
lappend ::connectionsMulticast[list $ipMulticast $port $socketMulticast]
#Open TCP unicast socket
set sockUnicast [socket $ipUnicast $port]
#configures the unicast port
fconfigure $sockUnicast -buffering none -translation binary;#(2)
#update the list of unicast connections with the socket
lappend ::connectionsMulticast[list $ipUnicast $port $socketUnicast]
#listen to the multicast socket, and forwarding the data to the unicast one
fileevent $sockMulticast readable [list ::dataForwarding $sockMulticast $sockUnicast]
}
}
proc dataForwarding {socketSrc socketDst} {
#get the data from the source socket, and place it on data
set data [read $socketSrc]
#placing the data in the destination socket
puts -nonewline $socketDst $data
return
}