Results 1 to 8 of 8

Thread: Help My File Transfer Can Only Send Up To 5Mb

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Help My File Transfer Can Only Send Up To 5Mb

    No idea what i did wrong... i can only send up to 6mb or else my program just exits itself on the client or host side whoever is sending how can i get it to send large files without getting this error?

    I took the code and modified from an example here is to send the data
    Code:
    Public Sub senddataa(sFile As String, sSaveAs As String, tcpCtl As Winsock)
    On Error GoTo ErrHandler
        Dim sSend As String, sBuf As String
        Dim ifreefile As Integer
        Dim lRead As Long, lLen As Long, lThisRead As Long, lLastRead As Long
        
        ifreefile = FreeFile
        
        ' Open file for binary access:
        Open sFile For Binary Access Read As #ifreefile
        lLen = LOF(ifreefile)
        
        ' Loop through the file, loading it up in chunks of 64k:
        Do While lRead < lLen
            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
            sSend = sSend & sBuf
        Loop
        lTotal = lLen
        Close ifreefile
        bSendingFile = True
        '// Send the file notification
        tcpCtl.senddata "FILE" & sSaveAs
        DoEvents
        '// Send the file
        tcpCtl.senddata sSend
        DoEvents
        '// Finished
        tcpCtl.senddata "FILEEND"
        bSendingFile = False
        Exit Sub
    ErrHandler:
        MsgBox "Err " & Err & " : " & Error
    End Sub
    and this is when the data arrives

    Code:
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
        Dim strData As String
        Dim ifreefile
        
        DoEvents
        Winsock1.getdata strData
        If Right$(strData, 7) = "FILEEND" Then
            bFileArriving = False
            lblProgress = "Saving File to " & App.Path & "\" & sFile
            sArriving = sArriving & Left$(strData, Len(strData) - 7)
            ifreefile = FreeFile
                Open sFile For Binary Access Write As #ifreefile
                Put #ifreefile, 1, sArriving
                Close #ifreefile
            lblProgress = "Complete"
        ElseIf Left$(strData, 4) = "FILE" Then
            bFileArriving = True
            sFile = Right$(strData, Len(strData) - 4)
        ElseIf bFileArriving Then
            lblProgress = "Receiving " & bytesTotal & " bytes for " & sFile & " from " & Winsock1.RemoteHostIP
            sArriving = sArriving & strData
        End If
    End Sub
    this is the code to send
    Code:
    senddataa txtFile, GetFileName(txtFile), Winsock1
    so senddataa thefile, sends the name and extension, and threw what connection, but it only sends like up to 6mb n crashes any ideas?

    EDIT: i get the error OUT OF STACK SPACE on DoEvents under Dim ifreefile
    Last edited by Evilribbet; Jan 7th, 2009 at 10:49 PM.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Help My File Transfer Can Only Send Up To 5Mb

    Do not put DoEvents in your DataArrival event. It's not necessary and it allows for unpredictable events to occur elsewhere. Once control enters the DataArrival control must remain in that event. Allow the Winsock control to enter this event whenever it decides to do so and don't mess with it. Also, you need a _Close event on both the client and the server. When control fires this event you close the socket for that application.

    Because of the way you have written your code I can only assume that you cause the senddataa sub to be fired only after you know for sure that you have actually connected to the other side.
    Last edited by jmsrickland; Jan 7th, 2009 at 11:05 PM.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Re: Help My File Transfer Can Only Send Up To 5Mb

    Thanks for the quick reply, i see as doevents is not needed as you explained , but also would i close the socket completly or leave it open once a file has sent? Like do you close the whole socket or?

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Help My File Transfer Can Only Send Up To 5Mb

    Quote Originally Posted by Evilribbet
    Thanks for the quick reply, i see as doevents is not needed as you explained , but also would i close the socket completly or leave it open once a file has sent? Like do you close the whole socket or?
    Send the data and then close the socket. Also, re-read my previous post.
    Code:
       '
       '
       '
    '// Finished
        tcpCtl.senddata "FILEEND"
        bSendingFile = False
        tcpCtl.Close
        Exit Sub
       '
       '
       '

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Help My File Transfer Can Only Send Up To 5Mb

    It's VB data type related. LOF() returns a Long... and the range of Long is around 4MB (unsigned).

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2007
    Posts
    53

    Re: Help My File Transfer Can Only Send Up To 5Mb

    Ok ok i see i tested it cuz i run it on 2 comp on my LAN but now it transfers really slow o.o?

    What would i change to send the data faster?
    Last edited by Evilribbet; Jan 7th, 2009 at 11:39 PM.

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Help My File Transfer Can Only Send Up To 5Mb

    Although VB is not multi-threaded, I believe your client-server is sending and receiving as fast as it can so it's not network related... the bottleneck would then be disk I/O, especially repetitive open/close of file. I suggest you buffer the data arrival so you write more per file open, or don't write per data arrival (pool it first).

  8. #8
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Help My File Transfer Can Only Send Up To 5Mb

    I use this to constantly download a 8.6 file:

    uses a progress bar
    Add reference to WinHTTP.dll in systems32. (Browse to it, if Microsoft WinHTTP services doesn't show on the references list.)

    Note this simple example doesn't do anything fancy, just dumps the downloaded bytes to disk.

    Code:
    OnResponseStart when you can safely access the headers.
    OnResponseDataAvailable which returns a byte array of downloaded data for each chunk. uses a progress bar
    OnResponseEnd which ends the download.
    
    
    Option Explicit
    Private WithEvents http As WinHttpRequest
    Private mContentLength As Long
    Private mProgress As Long
    
    Private Sub Command1_Click()
    ' Create the WinHTTPRequest ActiveX Object.
    Set http = New WinHttpRequest
    ' Open an HTTP connection.
    http.open "GET", "http://mysite/myfile.exe", True 'True means asynch.
    ' Send the HTTP Request.
    http.send
    End Sub
    
    Private Sub http_OnResponseDataAvailable(Data() As Byte)
    mProgress = mProgress + UBound(Data) + 1
    ProgressBar1.Value = mProgress
    
    Put #1, , Data
    
    
    End Sub
    
    Private Sub http_OnResponseFinished()
    Close #1
    MsgBox "done"
    End Sub
    
    Private Sub http_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)
    Text1.Text = http.getAllResponseHeaders()
    mProgress = 0
    mContentLength = CLng(http.getResponseHeader("Content-Length"))
    
    ProgressBar1.Max = mContentLength
    Open "C:\"Downloadedfile For Binary As #1
    
    End Sub
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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