CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2003
    Location
    AR
    Posts
    228

    Winsock sending file partially working, help!

    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 this, which was taken from another forum 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
            Loop
            
            Debug.Print SocketObject.State '-- show socket state (sckConnnected)
            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
            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.

    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?

    Moderators: please move to VB6 subforum, sorry!
    Last edited by Andrex; October 11th, 2010 at 12:16 PM. Reason: code cleaning

  2. #2
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Winsock sending file partially working, help!

    If one call to SendData sends 1000 bytes from the sending side, then how many bytes will one call to GetData receive on the receiving side?

    (a) 1000 bytes
    (b) 1 byte
    (c) any number of bytes from 1 single byte up to 1000 bytes

    The answer is (c). Does the code on the receiving side expect this?

    PS: The reason it works on a LAN is that through coincidence and chance, the answer is almost always (a) on a LAN, but the answer is almost always (c) on a WAN

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
  •  





Click Here to Expand Forum to Full Width

Featured