我想用vb6.0做个文件传送程序,使用tcp协议,用二进制方式读写文件,可是我用winsock的getdata方法来接收文件,则接收到的exe文件会没有用,文本文件则有用,且数据完整,如果我用winsock的peekdata方法接收文件,则接收到的文本文件会没有用,全部显示为乱码,而exe文件则有用,请问这是为什么?(请问有人有这方面的例子吗,如果有,麻烦上传来看看)谢谢

解决方案 »

  1.   

    Public Sub ReadFile(ByVal sFile As String, winsockUser As Winsock)
        '将文件读到字节数组并发送出去
        Dim oFSD As FileSystemObject
        Dim strError As String
        Dim oText As TextStream
        Dim aa() As Byte, array1() As Byte
        Dim i As Long, l As Long
        Dim Location, bb As String
        On Error Resume Next
        i = 0
        l = 0
        Open sFile For Binary Access Read Lock Read As #1
        Do While Location < LOF(1)
          ReDim Preserve array1(i)
          aa() = InputB(1, #1)
          Location = Loc(1)
          array1(l) = aa(0)
          l = l + 1
          i = i + 1
          DoEvents
        Loop
        'Debug.Print "l:"; l
        Close #1
        bolSend = False
        'TcpUser.SendData array1()
        winsockUser.SendData array1()
        Do Until bolSend
           DoEvents
        Loop
        'MsgBox "文件发送完毕!"
    End Sub
      

  2.   

    Public Sub WriteFile(fdata() As Byte, ByVal mfile As String, ByVal mfile_len As Long)
      '将字节数组中的数据写到文件中
        Dim oFSD As FileSystemObject
        Dim strError As String
        Dim loca, locab
        Dim sFile As String
        Dim fPath As String
        Dim bolFindIp As Boolean
        Dim i As Long, j As Long
        Dim pDwName As String
        On Error Resume Next
        sFile = mfile
        Open mfile For Binary Access Read Write As #2
        If LOF(2) = 0 Then
          loca = 1
        Else
          loca = LOF(2) + 1
        End If
         Seek #2, loca
        Put #2, , fdata()
        locab = LOF(2)
        If mfile_len = locab Then
          For i = 0 To UBound(FileArr(), 1)
            If FileArr(i, 5) = mfile Then
              pDwName = FileArr(i, 6)
              bolFindIp = True
              Exit For
            End If
          Next
          If bolFindIp Then
            fPath = Left(FileArr(i, 4), Len(FileArr(i, 4)) - 1)
            sFile = FileArr(i, 2)
            For j = 0 To UBound(FileArr(), 2)
             FileArr(i, j) = ""
            Next
          End If
          Close #2
          If sFile = "每日数据" Or sFile = "实时信息" Or sFile = "日数据" Then Call SetTabel(sFile, fPath, pDwName)
          'MsgBox "文件" & mfile & "接收完毕!"
        Else
          Close #2
        End If
    End Sub
      

  3.   

    最好客户端用put #,arrary()