1 Attachment(s)
File Transfers w/ Winsock
I know what you mean. I had the same problem with my program. The reason it won't transfer the files is that the server is sending the information to the client's winsock control so fast that it can't keep up. The winsock control on the server finishes sending the file long before it finishes arriving at the client. You have to add some timer code to your Do...Loop to reduce the amount of time between when winsock sends data. I've attached a file (both.zip) that I found somewhere that helped me out a lot. It includes both a server application and a client application. I wouldn't use their code verbatim as I don't totally agree with their programming style, however I borrowed a lot of concepts from them such as setting up certain commands to tell your programs to do different things such as 'sckServer.Send "OpenFile," & filename$' (You'll understand better if you study the code in this zip file). In this demo, they set the time to pause between sending data at 200. In my program, that wasn't enough. I'd recommend using about 500. I've had better luck with that number. Be sure to set a pause between each command you send back and forth as well as a pause between your Do...Loop. I think this should help you, but if you have any questions you can catch me on AIM. My s/n is Fulgore8292. You can also try e-mailing me at [email protected], however I don't check my e-mail very often. I'll also try to check this thread every so often to see if this helped or not. Good luck with your program! :)
File Transfer w/ Winsock (Update)
I'm glad that that zip file was helpful, but I made a mistake.
I recently realized that setting a Pause command in your Do...Loop will not only limit the maximum upload speed of your program, but it also doesn't always work. Instead of setting a Pause 500 command in your Do...Loop, it would be much better if you have the client tell the server when it's recieved the data. In other words, do something like this:
Do While lRead < lLen
Do
If Waiting = False then Exit Do
DoEvents
Loop
lThisRead = 65536
If lThisRead + lRead > lLen Then
lThisRead = lLen - lRead
End If
If Not lThisRead = lLastRead Then
sBuf = Space$(lThisRead)
End If
Get #ifreefile, , sBuf
lRead = lRead + lThisRead
tcpCtl.SendData sBuf
Waiting = True
DoEvents
Loop
You would have to add this to the general declarations section of your code...
Dim Waiting As Boolean
You would then add something like this to the DataArrival event of your winsock control on the server side...
Select Command$
Case "SendAgain"
Waiting = False
End Select
Next, add some code to your client program to send a command to the server telling it that it's ok to send more data like this...
sckClient.SendData "SendAgain,"
This should work much better than the Pause function.
I hope this helps. If you have any questions about this code, be sure to post them. :D
P.S. Don't try to load the whole file into a variable and send it all at once. First tell the client to open the file, send the file in small chunks like the above sample code, and then tell the client to close the file.