为何MD5总是读三遍,还有最后的数据库搜索到值了怎么还是要加载图片??
Static Size     As Long
On Error Resume Next
If Size = 0 Then
Open App.Path & "\MirGet(" & CStr(Index) & ").bmp" For Binary As #1
Size = 1
End If
TcpServer(Index).GetData B
TxtClientIP1.Text = TcpServer(Index).RemoteHostIP
TxtClientPort1.Text = TcpServer(Index).RemotePort
Size = Size + bytesTotal
If Size < 14454 Then
Put #1, , B
Else
Put #1, , B
Close #1
Size = 0
End If
TcpClient.Connect TxtClientIP1.Text, 2002
MD5 = HashFile(App.Path & "\MirGet(" & CStr(Index) & ").bmp")
If MirMdb.State = 1 Then MirMdb.Close
MirMdb.CursorLocation = adUseClient
MirMdb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\VB98\MirImage.mdb;Persist Security Info=False"
MirMdb.CommandTimeout = 30
MirMdb.Open
If MirRs.State <> adStateClosed Then MirRs.Close
MirRs.Open "SELECT * FROM MirImage01 Where MirMD5 = '" & MD5 & "'", MirMdb, adOpenStatic, adLockOptimistic
If MirRs.RecordCount >= 1 Then
TxtSend1.Text = MirRs.Fields("MirAnswer").Value
TcpClient.SendData TxtSend1.Text
Else
PicRecieve1.Picture = LoadPicture(App.Path & "\MirGet(" & CStr(Index) & ").bmp")
End If

解决方案 »

  1.   


    “读”三遍,是因为文件没有一次下载完成。每收到一包数据,就要重新计算文件的 MD5。如果在数据库中查到了 MD5 相符的记录,则发送记录中的 MirAnswer 值。否则在本机显示图片。
      

  2.   

    Private Sub TcpServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    Static Size     As Long
    If Size = 0 Then
        Open App.Path & "\MirGet(" & CStr(Index) & ").bmp" For Binary As #1
        Size = 1
    End If
    TcpServer(Index).GetData B
    TxtClientIP1.Text = TcpServer(Index).RemoteHostIP
    TxtClientPort1.Text = TcpServer(Index).RemotePort
    Size = Size + bytesTotal
    If Size >= 14454 Then          '改成传文件的大小
        Put #1, , B
        Close #1
        Size = 0
        TcpClient.Connect TxtClientIP1.Text, 2002
        MirMD5.Text = HashFile(App.Path & "\MirGet(" & CStr(Index) & ").bmp")
        MirMdb.CursorLocation = adUseClient
        MirMdb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\VB98\MirImage.mdb;Persist Security Info=False"
        MirMdb.CommandTimeout = 30
        MirMdb.Open
        If MirRs.State <> adStateClosed Then MirRs.Close
        MirRs.Open "SELECT * FROM MirImage01 Where MirMD5 = '" & MirMD5.Text & "'", MirMdb, adOpenStatic, adLockOptimistic
        If MirRs.RecordCount >= 1 Then
            TxtSend1.Text = MirRs.Fields("MirAnswer").Value
            TcpClient.SendData TxtSend1.Text
        Else
            PicRecieve1.Picture = LoadPicture(App.Path & "\MirGet(" & CStr(Index) & ").bmp")
            Beep 500, 100
        End If
    Else
        Put #1, , B
    End If
    End Sub
    这段代码如何改正确?