组播流到单播流tcl脚本问题

时间:2013-08-13 14:55:06

标签: eclipse-plugin tcl tk tclsh

我开始学习tcl脚本语言,我试图做一个tcl脚本,通过单播网络隧道传输所有组播数据包。

由于我是关于tcl的新手,我想问点:

  1. 我正在使用Eclipse在tcl中编码,我已经安装了所需的插件,我想也是所有的包,但是,Eclipse强调了我的以下调用

    fconfigure $sockMulticast -buffering none -mcastadd $ipMulticast -translation binary -remote [list $ipMulticast $port]
    

    说有额外的参数,我不明白,因为here可以阅读:

      Pat写道:“组播与标准单播有点不同   或广播UDP。您的操作系统会忽略多播数据包   除非应用程序已明确加入多播组。在里面   TclUDP的情况我们使用

    来做到这一点
    fconfigure $socket -mcastadd $mcastaddress
    
  2. 当我配置TCP套接字(单播)时,我应该在调用fconfigure时再次指定目标单播IP吗?

  3. 代码:

    #!/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
        }
    

1 个答案:

答案 0 :(得分:1)

关于第一点, Eclipse是完全错误的fconfigure命令可以使用任意数量的选项/值对(或单个选项来检索值,或者没有选项可以一次检索多个值 - 尽管不是必然所有;串行通道有一些奇怪的功能,但它们对你来说并不重要)。不幸的是他们错了,但它确实发生了。

关于第二点,我不会尝试更改TCP端点的IP地址;你不能这样做(严格来说,不是Tcl的绑定;如果你能这样做,我根本不知道)。 TCP和UDP通道对可更改的内容和时间有非常不同的限制(因为TCP通道使用握手协议在两个端口之间构建连接会话,而UDP根本没有这样的限制;作为回报,TCP通道可以视为可靠的流,而UDP根本不是流协议,没有会话/连接。)

您的lappend电话也遇到问题;你忽略了变量名和值附加到那些全局列表之间的关键空间。这意味着您期望保存连接信息列表的全局变量实际上不会这样做;相反,你将获得许多具有完全不切实际名称的奇怪变量。如果你添加IPv6支持(因为它可以在IP地址的呈现中使用::,它将完全破坏,尽管它也是一个Tcl命名空间分隔符)。立即修复它;为将来省去一点麻烦...

相关问题