5. 媒体服务传输控件 1) 类型 - 多播 一对多的文件传输, 接受者"监听"同一个多播IP地址和端口来接收文件. - 单播 一对一的文件传输, 接受者"监听"多个IP地址之一和同一个断开来接收文件.
2) 完全可靠性服务 文件传输组件实现了一个多播的完全可靠性服务保证每一个数据包被收到, 保持不被破坏和完整. 如果接受者发现数据包丢失和损坏, 可以发送一个NAK到发送者请求数据包重发.
在完全可靠性服务模式下, 文件传输服务执行一个流控制; 这是对于速度控制的额外支持. 如果发送者传输数据包过快, 接受者发送一个扼杀NAK提示传输速度必须下降. 接受者也在忙和无法接收更多数据包或者一段时间没有收到数据包的时候发送空闲 NAK.
文件传输控件使用完全可靠性服务模式作为缺省模式. 如果发送者不实用该模式, 控件依旧可以接收回传只是无法请求重传数据包. 完全可靠性服务可以通过 FullyReliableService 属性关闭.
双向网要求完全可靠服务.
完全可靠服务模式要求使用错误转发机制(FEC).
【相关控制消息】 - NAK 是一个发送自接收端到发送端的数据, 提示数据包被放弃. 是一个请求重发数据包的消息. 使用它是一个有效地方式添加可信度, 因为接受者只需要接收那些没有被接收的数据包. - Throttle NAK 来自接收端的请求, 提示发送端降低带宽. 被完全可靠服务使用. - Idle NAK 来自接收端的请求, 提示发送端在数据包没有收到, 且传输不完整. 发送端收到的时候等待其他接收端NKAs来重发请求的数据包.
3) 接收文件 方式: 1. 在发送者发送文件之前, 启动一个接收操作确保所有的文件被传输. 如果接收操作在发送到已经开始发送一组文件后开始, 接收端接收当前文件和其余文件. 如果接收动作在发送途中开始, 接收端接收该文件. 2. 使用 FtsStartFileTransferReceive 方法接收文件. 称之为监听. 针对多播传输, 使用一个多播地址. 针对多播传输使用主机的本地地址之一, 如果没有指定本地地址, 第一个主机本地地址缺省使用. 接收端可以取消一个文件接收(FtsCancelFileTransferReceive). 状态和进度可以通过事件和属性在文件传输期间获得.
4) 状态提示 FtsOnTransferStarted FtsOnTransferCompleted FtsOnFileTransferStarted FtsOnFileTransferCompleted FtsOnStatusChanged
5) 进度提示 要获得文件传输信息, 使用 FtsRegisterStatusCallback 注册需要的传输信息. 典型的请求包括 - 每100KB提示一次, 获则每10%提示一次.
提示也可以请求关于接收的数据包个数, 虚假数据包个数( 从同一个IP地址和端口获得, 但是不是需要的文件部分), 重复数据包, 丢失数据包等. 进度提示由 FtsOnTransferProgress 事件处理. 读取正确的属性, 然后在事件处理子程序中采取正确的处理. 通过调用 FtsRevokeStatusCallback 方法可以宣告一个提示无效.
进度通告只在 FtsOnTransferProgress 时间上触发. 传输进度属性值 (诸如: NumPacketsDropped)总是有效地.
6) 如何使用 <OBJECT ID="NSFile" WIDTH="100" HEIGHT="51" CLASSID="CLSID:26F24A93-1DA2-11D0-A334-00AA004A5FC5" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsftsinf.cab#Version=3,0,0,2700"></OBJECT>
<!-- 一个接收文件的例子, 附带进度显示 --> <SCRIPT LANGUAGE="VBScript"> <!-- Sub BtnReceiveFile_OnClick MyForm.Noise.Value = 0 MyForm.Redundancy.Value = 0 call nsfile1.FtsRegisterStatusCallback(0, 0, 4096, 4096, 0, 0, 0, 0, 0, 0, 0) On Error Resume Next call nsfile1.FtsStartFileTransferReceive("239.230.50.50", 5050, "", "%TEMP%\", 0, 1025) IfErr.Number Then MsgBox "Start Error = " & ReturnError(Err.Number) End Sub
Sub BtnCancelFile_OnClick call nsfile1.FtsCancelFileTransferReceive MsgBox "Transfer Cancelled. Error = " & ReturnError(nsfile1.Result) End Sub
Sub nsfile1_FtsOnTransferProgress MyForm.TotalBytes.Value = nsfile1.NumTotalBytesTransferred MyForm.DataBytes.Value = nsfile1.NumTotalDataBytesTransferred MyForm.Packets.Value = nsfile1.NumPacketsTransferred MyForm.Bogus.Value = nsfile1.NumBogusPacketsReceived End Sub
Sub nsfile1_FtsOnTransferCompleted MsgBox "Transfer Completed. Error = " & ReturnError(nsfile1.Result) TotalBytes = nsfile1.NumTotalBytesTransferred if TotalBytes > 0 then DataBytes = nsfile1.NumTotalDataBytesTransferred MyForm.Redundancy.Value = Int(((TotalBytes - DataBytes)/TotalBytes)*100) Packets = nsfile1.NumPacketsTransferred Bogus = nsfile1.NumBogusPacketsReceived MyForm.Noise.Value = Int(Bogus/Packets) MyForm.TotalBytes.Value = nsfile1.NumTotalBytesTransferred MyForm.DataBytes.Value = nsfile1.NumTotalDataBytesTransferred MyForm.Packets.Value = nsfile1.NumPacketsTransferred MyForm.Bogus.Value = nsfile1.NumBogusPacketsReceived end if End Sub
Sub BtnAbout_OnClick call nsfile1.AboutBox() End Sub
Function ReturnError(ByVal ErrNum) Select Case ErrNum Case 0 ErrString = "No Error" Case 1 ErrString = "Already Requested" Case -2147467260 ErrString = "Cancelled" Case -2147467259 ErrString = "Failed" Case -2147287038 ErrString = "File Not Found" Case -2147024882 ErrString = "Out Of Memory" Case -2147024809 ErrString = "Invalid Parameter" Case -2147023436 ErrString = "Timed Out" Case Else ErrString = "Unknown Error " & CStr(Hex(ErrNum)) End Select ReturnError = ErrString End Function
--> </SCRIPT>
<!-- 一个完整的接收文件例子 --> <HTML> <HEAD><TITLE>Total FTS Demo</TITLE> <link rel="stylesheet" type="text/css" href="../msdn_ie4.css"> </HEAD> <BODY BGCOLOR="#FFFFFF">
<H2>Total File Transfer Service Demo</H2>
<OBJECT ID="nsfile1" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsftsinf.cab#Version=3,0,0,2700" CLASSID="CLSID:26F24A93-1DA2-11D0-A334-00AA004A5FC5" ALIGN="RIGHT" HEIGHT="10" WIDTH="10"> <PARAM NAME="_Version" VALUE="65536"> <PARAM NAME="_ExtentX" VALUE="2646"> <PARAM NAME="_ExtentY" VALUE="1323"> <PARAM NAME="_StockProps" VALUE="0"> </OBJECT>
<FORM NAME="MyForm"> <TABLE> <TR> <TD><B>Source IP:</B></TD><TD><INPUT TYPE="TEXT" NAME="IPAddr" VALUE="239.230.50.50"></TD> <TD><B>Source port:</B></TD><TD><INPUT TYPE="TEXT" NAME="IPPort" VALUE="5050" SIZE="6"></TD> <TD><B>Filter:</B></TD><TD><INPUT TYPE="TEXT" NAME="Filter"></TD> </tr> </TABLE> <HR SIZE=1>
<TABLE> <TR> <TD><B>Path:</B></TD><TD><INPUT TYPE="TEXT" NAME="FilePath" VALUE="%TEMP%\"></TD> <TD><B>Attributes:</B></TD><TD><INPUT TYPE="TEXT" NAME="Attributes" VALUE="0"></TD> <TD><B>Flags:</B></TD><TD><INPUT TYPE="TEXT" NAME="Flags" VALUE="1025"></TD> </TR> </TABLE> <HR SIZE=1>
<TABLE> <TR> <TD><INPUT TYPE="BUTTON" NAME="BtnReceiveFile" VALUE="Start receive"></TD> <TD><INPUT TYPE="BUTTON" NAME="BtnCancelFile" VALUE="Cancel"></TD> <TD><INPUT TYPE="BUTTON" VALUE="About FTS" NAME="BtnAbout"></TD> <TD WIDTH="25"></TD> <TD WIDTH="50"><INPUT TYPE="TEXT" NAME="Routing"></TD> <TD WIDTH="25"></TD> <TD ALIGN="RIGHT" WIDTH="75"><B>Start time:</B></TD> <TD WIDTH="150"><INPUT TYPE="TEXT" NAME="StartTime"></TD> </TR> </TABLE> <HR SIZE=1>
<TABLE> <TR> <TD><B>Files:</B></TD><TD><INPUT TYPE="TEXT" NAME="NumFiles" SIZE="5"></TD> <TD><B>Percent file:</B></TD><TD><INPUT TYPE="TEXT" NAME="PerFileData" SIZE="30"></TD> <TD><B>Time taken:</B></TD><TD><INPUT TYPE="TEXT" NAME="MyTime"></TD> </TR> </TABLE> <HR SIZE=1>
<TABLE> <TR> <TD><B>Current file:</B></TD><TD><INPUT TYPE="TEXT" NAME="CurrFile" SIZE="30"></TD> <TD><B>Size:</B></TD><TD><INPUT TYPE="TEXT" NAME="CurrSize" SIZE="16"></TD> <TD><B>Attributes:</B></TD><TD><INPUT TYPE="TEXT" NAME="CurrAttr" SIZE="6"></TD> </TR> </TABLE> <HR SIZE=1>
<TABLE> <TR> <TD><B>Total bytes:</B></TD><TD><INPUT TYPE="TEXT" NAME="TotalBytes"></TD> <TD><B>Data bytes:</B></TD><TD><INPUT TYPE="TEXT" NAME="DataBytes"></TD> </TR> <TR> <TD><B>Packets:</B></TD><TD><INPUT TYPE="TEXT" NAME="Packets" SIZE="8"></TD> <TD><B>Bogus:</B></TD><TD><INPUT TYPE="TEXT" NAME="Bogus" SIZE="8"></TD> <TD><B>Drop:</B></TD><TD><INPUT TYPE="TEXT" NAME="PackDrop" SIZE="8"></TD> </tr> <TR> <TD><B>Corr:</B></TD><TD><INPUT TYPE="TEXT" NAME="PackCorr" SIZE="8"></TD> <TD><B>Dupes:</B></TD><TD><INPUT TYPE="TEXT" NAME="PackDup" SIZE="8"></TD> </TR> </TABLE> <HR SIZE=1>
<TABLE> <TR> <TD><B>Source path:</B></TD><TD><INPUT TYPE="TEXT" NAME="SrcPath" SIZE="35"></TD> </tr> <TR> <TD><B>Destination path:</B></TD><TD><INPUT TYPE="TEXT" NAME="DestPath" SIZE="35"></TD> </TR>
<TR> <TD><B>Endpoint address:</B></TD><TD><INPUT TYPE="TEXT" NAME="EndAddr" SIZE="16"></TD> <TD><B>Endpoint port:</B></TD><TD><INPUT TYPE="TEXT" NAME="EndPort" SIZE="8"></TD> </TR>
<TR> <TD><B>Source addresss:</B></TD><TD><INPUT TYPE="TEXT" NAME="SrcAddr" SIZE="16"></TD> <TD><B>Source port:</B></TD><TD><INPUT TYPE="TEXT" NAME="SrcPort" SIZE="8"></TD> </TR>
<TR> <TD><B>Local address:</B></TD><TD><INPUT TYPE="TEXT" NAME="LocAddr" SIZE="16"></TD> <TD><B>Local port:</B></TD><TD><INPUT TYPE="TEXT" NAME="LocPort" SIZE="8"></TD> </tr> <TR> <TD><B>Local port used:</B></TD><TD><INPUT TYPE="TEXT" NAME="LastPort" SIZE="16"></TD> </TR> </TABLE> <HR SIZE=1>
</FORM>
<SCRIPT LANGUAGE="VBScript"> <!-- Sub BtnReceiveFile_OnClick On Error Resume Next '--- Initialize form values. MyForm.MyTime.Value = "" MyForm.StartTime.Value = "" MyForm.NumFiles.Value = "" MyForm.PerFileData.Value = "" MyForm.TotalBytes.Value = "" MyForm.DataBytes.Value = "" MyForm.CurrFile.Value = "" MyForm.CurrAttr.Value = "" MyForm.CurrSize.Value = "" MyForm.Packets.Value = "" MyForm.Bogus.Value = "" MyForm.PackDrop.Value = "" MyForm.PackCorr.Value = "" MyForm.PackDup.Value = "" MyForm.SrcPath.Value = "" MyForm.DestPath.Value = "" MyForm.EndAddr.Value = "" MyForm.EndPort.Value = "" MyForm.SrcAddr.Value = "" MyForm.SrcPort.Value = "" MyForm.LocAddr.Value = "" MyForm.LocPort.Value = "" MyForm.LastPort.Value = "" '--- Determine routing. If MyForm.IPAddr.Value = "" Then MyForm.Routing.Value = " Listen for Unicast" MyIPAddr = "" nsfile1.Type = 2 Else MyIPAddr = MyForm.IPAddr.Value MyForm.Routing.Value = "Listen for Multicast" End If '--- Set up callbacks. call nsfile1.FtsRegisterStatusCallback(4096, 5, 8192, 8192, 1, 1, 1, 1, 1, 4+8+16+32, 0) '--- Start transfer. call nsfile1.FtsStartFileTransferReceive(MyIPAddr, MyForm.IPPort.Value, MyForm.Filter.Value,MyForm.FilePath.Value, MyForm.Attributes.Value, MyForm.Flags.Value) If Err.Number Then MsgBox "Start Error = " & ReturnError(Err.Number) End Sub
Sub BtnCancelFile_OnClick On Error Resume Next call nsfile1.FtsCancelFileTransferReceive MsgBox "Transfer Cancelled. Error = " & ReturnError(nsfile1.Result) End Sub
Sub nsfile1_FtsOnTransferStarted On Error Resume Next MyForm.StartTime.Value = Time() MyForm.SrcPath.Value = nsfile1.SourceFilePath MyForm.DestPath.Value = nsfile1.DestinationFilePath MyForm.EndAddr.Value = nsfile1.EndpointAddress MyForm.EndPort.Value = nsfile1.EndpointPort MyForm.SrcAddr.Value = nsfile1.SourceAddress MyForm.SrcPort.Value = nsfile1.SourcePort MyForm.LocAddr.Value = nsfile1.LocalAddress MyForm.LocPort.Value = nsfile1.LocalPort MyForm.LastPort.Value = nsfile1.LocalPortUsed End Sub
Sub nsfile1_FtsOnFileTransferStarted On Error Resume Next MyForm.CurrFile.Value = nsfile1.CurrentFilePath MyForm.CurrAttr.Value = nsfile1.CurrentFileAttributes MyForm.CurrSize.Value = nsfile1.CurrentFileSize End Sub
Sub nsfile1_FtsOnFileTransferCompleted On Error Resume Next MyForm.NumFiles.Value = nsfile1.NumFilesTransferred End Sub
Sub nsfile1_FtsOnTransferProgress On Error Resume Next MyForm.NumFiles.Value = nsfile1.NumFilesTransferred ProgBar = Int((nsfile1.PercentFileDataBytesTransferred)/5) If ProgBar < 20 Then MyForm.PerFileData.Value = String(ProgBar, "?) Else MyForm.PerFileData.Value = "File Transferred!" End If MyForm.TotalBytes.Value = nsfile1.NumTotalBytesTransferred MyForm.DataBytes.Value = nsfile1.NumTotalDataBytesTransferred MyForm.Packets.Value = nsfile1.NumPacketsTransferred MyForm.Bogus.Value = nsfile1.NumBogusPacketsReceived MyForm.PackDrop.Value = nsfile1.NumPacketsDropped MyForm.PackCorr.Value = nsfile1.NumPacketsCorrected MyForm.PackDup.Value = nsfile1.NumDuplicatePacketsReceived End Sub
Sub nsfile1_FtsOnTransferCompleted On Error Resume Next TTime = TimeValue(Now) - TimeValue(MyForm.StartTime.Value) MyForm.MyTime.Value = "Total = " & Hour(TTime) & " h " & Minute(TTime) & " m " & Second(TTime) & " s" MsgBox "Transfer Completed. Error = " & ReturnError(nsfile1.Result) '--- Bytes MyForm.NumFiles.Value = nsfile1.NumFilesTransferred MyForm.PerFileData.Value = "File Transferred!" MyForm.TotalBytes.Value = nsfile1.NumTotalBytesTransferred MyForm.DataBytes.Value = nsfile1.NumTotalDataBytesTransferred MyForm.CurrFile.Value = nsfile1.CurrentFilePath MyForm.CurrAttr.Value = nsfile1.CurrentFileAttributes MyForm.CurrSize.Value = nsfile1.CurrentFileSize '--- Packets MyForm.Packets.Value = nsfile1.NumPacketsTransferred MyForm.Bogus.Value = nsfile1.NumBogusPacketsReceived MyForm.PackDrop.Value = nsfile1.NumPacketsDropped MyForm.PackCorr.Value = nsfile1.NumPacketsCorrected MyForm.PackDup.Value = nsfile1.NumDuplicatePacketsReceived End Sub
Sub BtnAbout_OnClick call nsfile1.AboutBox() End Sub
Function ReturnError(ByVal ErrNum) Select Case ErrNum Case 0 ErrString = "No Error" Case 1 ErrString = "Already Requested" Case -2147467260 ErrString = "Cancelled" Case -2147467259 ErrString = "Failed" Case -2147287038 ErrString = "File Not Found" Case -2147024882 ErrString = "Out Of Memory" Case -2147024809 ErrString = "Invalid Parameter" Case -2147023436 ErrString = "Timed Out" Case Else ErrString = "Unknown Error " & CStr(Hex(ErrNum)) End Select ReturnError = ErrString End Function --> </SCRIPT>
</BODY> </HTML>
|