|
-
Oct 11th, 2010, 11:50 AM
#1
Thread Starter
New Member
Winsock file transfer issue (through Internet only?)
Hi, I'm using the Winsock OCX in VB6 to create a personal file server application, and it transfer files perfectly within the LAN, but not the Internet. If I access it via localhost or the machine name over LAN, it works perfect. But when accessing via the Internet IP, only the first block of the file arrives to the user's browser. However it is entirely sent, no errors appear in the server application. 
The main code to send the file is below, taken from DigiRev's Send File With Winsock code and modified to make it politely wait for the SendComplete event before sending the next chunk of data. Didn't fix the problem anyway.
Code:
Open FilePath For Binary Access Read As #lonFF
ReDim bytData(1 To PacketSize) As Byte
Do Until (lonSize - lonCurByte) < PacketSize
Get #lonFF, lonCurByte + 1, bytData()
lonCurByte = lonCurByte + PacketSize
Do While sendComplete = False
DoEvents '-- wait for the sendComplete event from winsock (using a flag)
Loop
Debug.Print SocketObject.State '-- show socket state (sckConnected)
Debug.Print "Sending block " & lonCurByte
sendComplete = False
SocketObject.SendData bytData()
DoEvents
Loop
lonPrevSize = lonSize - lonCurByte
If lonPrevSize > 0 Then
ReDim bytData(1 To lonPrevSize) As Byte
Get #lonFF, lonCurByte + 1, bytData()
lonCurByte = lonCurByte + lonPrevSize
Do While sendComplete = False
DoEvents '-- wait for the sendComplete event from winsock (using a flag)
Loop
Debug.Print SocketObject.State '-- show socket state (sckConnnected)
Debug.Print "Sending final block..."
sendComplete = False
SocketObject.SendData bytData()
DoEvents
End If
Close #lonFF
Also tried with the UniSock API and the result is the same. And I used the Winsock repair utility just in case, of course it was useless. Also tried all possible block sizes: 1024, 2048, 4096, 8192... always the first block arrives to destination, and the browser keeps "Loading..." forever.
ANY help wil be greatly appreciated. I'm not sending any headers before sending the file, I've tried that but didn't fix anything. And if it works OK over LAN, why it fails when accessing the server using the Internet IP?
Last edited by Inuya5ha; Oct 11th, 2010 at 12:09 PM.
Reason: code cleaning
-
Oct 11th, 2010, 12:49 PM
#2
Re: Winsock file transfer issue (through Internet only?)
I suspect the problem is not with the sending,more likely with the receiving. Can you post the receiving code (ie the winsock_dataarrival code)?
-
Oct 11th, 2010, 01:12 PM
#3
Re: Winsock file transfer issue (through Internet only?)
Not sure what example you went by, but there is no need for any DoEvents calls in proper Winsock code. You've written this is some sort of pseudo-blocking fashion. Your "triggering" event handler should just open the file and send the first block. Subsequent blocks (and file close after EOF) would be done within the SendComplete event handler.
I agree that your root problem is most likely in the receving code though.
-
Oct 12th, 2010, 11:37 AM
#4
Thread Starter
New Member
Re: Winsock file transfer issue (through Internet only?)
Thanks, I've taken the code just as suggested here and it seems the code is correct and works.
I have no receiving code, that would be Firefox and Internet Explorer, because my program servers the pages with the content in an FTP-fashion (via HTTP of course) and sends the requested file to to browser.
Are you suggesting that I send the rest of the blocks of the file from the SendComplete event itself? I doubt that will make any difference... please try to explain because my english might not be good enough to understand, sorry!
Thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|