Results 1 to 4 of 4

Thread: Socket file corruption [RESLVD]

Threaded View

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Socket file corruption [RESLVD]

    Allright, this is my first attempt at sending a file over winsock ... heres my code

    CLIENT
    Code:
    Private Sub sendPicture(strFileName As String)
    
     Dim picMain As New StdPicture
    
        Dim fileLEN As Long
        Dim byteChunk(999) As Byte
        
    
        Open strFileName For Binary As #1
        
        sckSocket.SendData "[FIS]" & LOF(1)
        
        fileLEN = LOF(1)
        
        While (fileLEN >= 0)
        
        DoEvents
            Get 1, , byteChunk()
            fileLEN = fileLEN - 1000
            
            If (fileLEN > 0) Then
            
                sckSocket.SendData sndChunk()
                sckSocket.SendData byteChunk()
            
            Else
                
                sckSocket.SendData endChunk()
                sckSocket.SendData byteChunk()
                
            
            End If
        Wend
        Close #1
     
        MsgBox "Send complete!"
    End Sub

    SERVER
    Code:
            
        If (Left(Data, 5) = "[FIS]") Then
        
            Data = cutLData(Data, 5)
            getFileIndex = 0
            totalSize = Data
            ReDim getFile(0 To (totalSize + 2000)) 'need fix +2000, keeps giving (out of bound error)
               
            With frmVote 'ignore me, display only
                
                .Show
                .frameVote.Visible = False
                .frameGetFile.Visible = True
                .lblTotalSize.Caption = "Total size: " & Val(Data)
            End With
           
            
            
        ElseIf (Left(Data, 5) = "[FIL]") Then
        
            Data = cutLData(Data, 5)
            
    
            For i = 1 To Len(Data) - 1
                getFile(getFileIndex) = Asc(Mid(Data, i, 1))
                getFileIndex = getFileIndex + 1
            Next i
            
            
            frmVote.lblGotSize = "Got: " & getFileIndex & " bytes"
            
            
        ElseIf (Left(Data, 5) = "[FIE]") Then
            
            Dim intTrim As Integer
            
            intTrim = totalSize - getFileIndex
            Data = cutLData(Data, 5)
            Trim Data
            
            For i = 1 To Len(Data) - 1 - (intTrim) '(OOB) here, ***?
                getFile(getFileIndex) = Asc(Mid(Data, i, 1))
                getFileIndex = getFileIndex + 1
            Next i
            
            Open "c:\test.jpg" For Binary As #2
            Put #2, , getFile
            Close #2
            frmVote.lblGotSize = "Got: " & getFileIndex & " bytes (done!)"
        
        End If
    When i get the picture on the other side, its really corrupt... I mean the effect is cool and all but its not what I'm going for

    What am i doing wrong, AND am i doing this really inefficently?
    I tried to poke around the forum for sending around files but didnt really come accross anything good so i came up with my own way of doing it...

    some variables are declared globaly, so just assume they work.

    Any help would be good, thanks!
    Last edited by invitro; Mar 27th, 2004 at 08:56 PM.
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

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