Results 1 to 4 of 4

Thread: winsock wont receive full file

  1. #1

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919

    winsock wont receive full file

    VB Code:
    1. Private Sub sckDownload_DataArrival(ByVal bytesTotal As Long)
    2.     Dim Pos                             As Integer
    3.     Dim LENGTH                          As Integer
    4.     Dim HEAD                            As String
    5.     Debug.Print bytesTotal
    6.    
    7.     Dim m_sData() As Byte
    8.    
    9.      sckDownload.GetData m_sData(), vbByte
    10.      'sckDownload.GetData m_sDATA, vbString
    11.      
    12.      Debug.Print "receiving data"
    13.      
    14.      If InStr(LCase(m_sData), "content-type:") Then         If RESUMEFILE = True Then 'check to see if its gonna resume ok or not..This is actually the worst way to check this.
    15.              If InStr(LCase(m_sData), "206 partial content") = 0 Then
    16.                  MsgBox "Server did not accept resuming.", vbCritical, "No Resuming Support"
    17.                  Reset
    18.                  CloseSocket
    19.                  Exit Sub
    20.                  End If
    21.             End If
    22.      
    23.          If InStr(LCase(m_sData), "404 not found") > 0 Then
    24.              MsgBox "The file requested was not found on the server!" & vbCrLf & vbCrLf & "Possible Reasons:" & vbCrLf & "- File Does Not Exist On Server" _
    25.              & vbCrLf & "- URL Given Was Script And Data Returned Was Invalid" & vbCrLf & "- URL Entered Was Incorrect" & vbCrLf & "- Server Is Excessively Busy" _
    26.              & vbCrLf & vbCrLf & "You may reattempt to download.  If its still failure then most likely invalid url.", , "File Not Found"
    27.              Reset
    28.              CloseSocket
    29.              Exit Sub
    30.          End If
    31.    
    32.          Pos = InStr(m_sData, vbCrLf & vbCrLf) ' find out where the header and the data is split apart
    33.          LENGTH = Len(CStr(m_sData)) 'get the length of the data chunk
    34.          HEAD = Left(m_sData, Pos - 1) 'Get the header from the chunk of data and ignore the data content
    35.          m_sData = Right(m_sData, LENGTH - Pos - 3) 'Get the data from the first chunk that contains the header also
    36.          Header = Header & HEAD 'Append the header to header text box
    37.          
    38.          If RESUMEFILE = True Then
    39.              BytesAlreadySent = FileLength + 1
    40.              BytesRemaining = GETDATAHEAD(Header, "Content-Length:")
    41.              BytesRemaining = BytesRemaining + FileLength
    42.          Else
    43.              BytesRemaining = GETDATAHEAD(Header, "Content-Length:")
    44.          End If
    45.          
    46.          Debug.Print "length: " & BytesRemaining
    47.          Debug.Print Header
    48.      End If
    49.      '-----------BEGIN WRITE CHUNK TO FILE CODE--------
    50.      Debug.Print "appending to file"
    51.      Open FilePathName For Binary Access Write As #1 'opens file for output
    52.      Put #1, BytesAlreadySent, m_sData 'writes data to the end of file
    53.      BytesAlreadySent = Seek(1)
    54.      Close #1 'close file for now until next data chunk is available
    55.      '--------------------------------------------------
    56.      
    57.      If RESUMEFILE = False Then
    58.               transferrate = Format(Int(BytesAlreadySent / (Timer - BeginTransfer)) / 1000, "####.00")
    59.      Else
    60.                 transferrate = Format(Int((BytesAlreadySent - FileLength) / (Timer - BeginTransfer)) / 1000, "####.00")
    61.      End If
    62.      Debug.Print "transfer rate: " & transferrate
    63. End Sub
    64.  
    65.  
    66. Private Sub sckDownload_Connect()
    67. On Error Resume Next
    68.     Dim strCommand                      As String
    69.    
    70.     Debug.Print "connected"
    71.    
    72.     'Right(URL, Len(URL) - Len(strSvrURL) - 7)
    73.     strCommand = "GET " + URL + " HTTP/1.1" + vbCrLf
    74.     strCommand = strCommand + "Accept: video/mpeg , video/avi" + vbCrLf
    75.    
    76.     If RESUMEFILE = True Then
    77.         strCommand = strCommand + "Range: bytes=" & FileLength & "-" & vbCrLf
    78.     End If
    79.    
    80.     strCommand = strCommand + "User-Agent: Video Crawler" & vbCrLf
    81.     strCommand = strCommand + "Referer: " & strSvrURL & vbCrLf
    82.     strCommand = strCommand + "Host: " & strSvrURL & vbCrLf
    83.    
    84.     strCommand = strCommand + vbCrLf
    85.    
    86.     Debug.Print strCommand
    87.     sckDownload.SendData strCommand 'sends a header to the server instructing it what to do!
    88.     BeginTransfer = Timer 'start timer for transfer rate
    89. End Sub


    RESUMEFILE = FALSE, always

    it does the same thing then m_sData was a string

    it receives 10-256 bytes, and no more
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    When i wsa transfering a file with winsock.. i came to know that I doesn't support a packet larger than 4K...

  3. #3

    Thread Starter
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    how?

    windows also uses winsock, the winsock control is just a wrapper for the winsock api.

    if it is 4k packets, how do i decrease the packet size?
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  4. #4
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    What i did.. I opened the file read 4000 bytes out of it.. put them in a Byte Array.. i also appended 96 bytes for information about file (like packet #, total packets, packet size, file size etc).. and then sent it thru.. SendData..
    at the other end.. When the first packet was received.. i opened another file there.. and put the last 4000 bytes from that array into that file...at the arrival of last packet.. i closed the file.. and that's all./.

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