Winsock sending file partially working, help!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Winsock sending file partially working, help!

Threaded View

  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

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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center