Winsock File-Transfer problems
Hello,
I am sorry if I am asking stupid questions, but I searched the entire web but couldn't find out what was wrong about my VB6 code:
It's purpose is to send a file to a client, but the file get's damaged every time :(
Does anyone know what is wrong? Thank you very much!
-There is a Winsock control on my form called SendFile
-The var Ready becomes true when the SendData event is fired.
Client Code:
Open FileName For Binary As #Filenum
If pos = 0 Then
Put #Filenum, 1, Buffer
Else
Put #Filenum, pos, Buffer
End If
pos = pos + Len(Buffer)
Close #Filenum
Server Code:
in top:
Private Const chunk = 8192
In event:
Open Filename For Binary As #FileNum
FileLen = 0
Do While Not EOF(FileNum)
If FileLen + chunk > LOF(FileNum) Then
Dim Diff
Diff = LOF(FileNum) - FileLen
data = Input(Diff, #FileNum)
FileLen = FileLen + Diff
Else
data = Input(chunk, #FileNum)
FileLen = FileLen + chunk
End If
Do Until Ready = True
DoEvents
Loop
SendFile.SendData data
DoEvents
Loop
Close #FileNum