我作了一个局域网文件传输软件,传后的文件不能打开(比如*.avi,*.mp3),百思不的其解,还请高手指教,程序如下:  Open SrcPath For Binary As #1
    If nLoop > 0 Then
        For Cn = 1 To nLoop
            BufFile = String(8192, " ")
            Get #1, , BufFile
            WskClient.SendData BufFile
            IsReceived = False
            lbByteSend.Caption = "传输状态: " & Cn * 81092 & " Of " & LnFile
            lbByteSend.Refresh
            While IsReceived = False
                DoEvents
            Wend
        Next
        If nRemain > 0 Then
            BufFile = String(nRemain, " ")
            Get #1, , BufFile
            WskClient.SendData BufFile
            IsReceived = False
            lbByteSend.Caption = "传输状态: " & LnFile & " Of " & LnFile
            lbByteSend.Refresh
            While IsReceived = False
                DoEvents
            Wend
        End If
    Else
        BufFile = String(nRemain, " ")
        Get #1, , BufFile
        WskClient.SendData BufFile
        IsReceived = False
        While IsReceived = False
            DoEvents
        Wend
    End If
    WskClient.SendData "Msg_Eof_"    'end of file tag
    Close #1
    Exit Sub
GLocal:
    MsgBox Err.Description
    
End Sub

解决方案 »

  1.   

    接收代码如下,小文件字节数相等还请指点
    Private Sub WskServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)
        Dim RecBuffer As String
        Dim Ret As Integer
        
        On Error GoTo GLocal
        
        WskServer(Index).GetData RecBuffer
        Select Case Left(RecBuffer, 8)
            Case "Msg_Eof_"
                Close #FL
                lblInfo.Caption = "正在接收..."
            Case "Msg_Dst_"
                DstPath = Right(RecBuffer, Len(RecBuffer) - 8)
                    
                FL = FreeFile
                'overwrite file
                On Error Resume Next
                If Len(Dir(DstPath)) > 0 Then
                    Ret = MsgBox("文件已经存在!!!" & vbCrLf & " 你向覆盖吗??", vbQuestion + vbYesNo, "提醒")
                    If Ret = vbYes Then
                        Kill DstPath
                    Else
                        'insert code to notify the error
                        'to client
                        Unload Me
                    End If
                End If
                Open DstPath For Binary As #FL
                lbFilereceived.Caption = DstPath
                WskServer(Index).SendData "Msg_OkS"
            
            Case Else
                BytesRec = BytesRec + Len(RecBuffer)
                Put #FL, , RecBuffer
                lbBytesReceived.Caption = "接收: " & BytesRec
                WskServer(Index).SendData "Msg_Rec"
        End Select
        
        Exit Sub
    GLocal:
        MsgBox Err.Description
        Unload Me
        
    End Sub
      

  2.   

    hsn1982(我 爱 猫 猫)我还是没解决,还望赐教
      

  3.   

    这个问题还是一个老问题,我做过一个同样的东东 ,传200m的文件都没有问题。用byte数组接受和发送数据
      

  4.   

    上面这位大哥能否把源程序赐之。万分感谢!!![email protected]
      

  5.   

    buffer 定义成string当然不行了!
    定义成字节数组!!
      

  6.   

    用string 的只能传字符,用字节数组能传任何的文件
      

  7.   

    发送端:
    Dim buffer() As Byte
    '读文件
    filelens = FileLen(Text2.Text)
      ReDim buffer(filelens - 1)
      Open Text2.Text For Binary As #3
      Get #3, 1, buffer
      Close #3
    '发送
    Winsock1.SendData (buffer)
    接受端:
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim buffer() As Byte
    Winsock1.GetData buffer
    Put #3, getlen, buffer
      getlen = getlen + UBound(buffer) + 1
    End Sub
    具体细节你自己看着办吧,比如close #3
      

  8.   

    请问kink(林) 怎样判断否剖传完可呢??
      

  9.   

    下面是用数组方式,可大小无误的传送,但还有一难点:
    SEND>>>
    Private Sub Command2_Click()
    Dim FileArray() As Byte
    Dim lnfile As Long
    Dim srcpath As String
    srcpath = "F:\美国音乐大典\Avseq10.avi"
    Text1.Text = FileLen(srcpath)
    Open srcpath For Binary As #1 
            lnfile = FileLen(srcpath) '获的文件大小但怎样传到服务端呢?
        ReDim FileArray(lnfile)    
        Get #1, , FileArray
        Winsock1.SendData FileArray
        Close #1
    End Sub
    接受端:
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim getArray() As Byte
    Dim data As String
    ReDim getArray(bytesTotal)
    Winsock1.GetData getArray
    FileCount = FileCount + bytesTotal
    Label1.Caption = CStr(Int(FileCount * 100 / 682413)) + " %" 
    If FileCount <= 682413 + 1 Then '682413是文件实际大小,但怎样获得呢??
        Put #1, , getArray
    Else
        Close #1
        Label1.Caption = "Receive OK!"End If
    End Sub
      

  10.   

    在线等待>>>>>>>>>