Results 1 to 3 of 3

Thread: question on this function i found

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    question on this function i found

    VB Code:
    1. Public Sub SendFile(SocketObject As Variant, ByVal FilePath As String, ByVal PacketSize As Long)
    2.     Dim lonFF As Long, bytData() As Byte
    3.     Dim lonCurByte As Long, lonSize As Long
    4.     Dim lonPrevSize As Long
    5.    
    6.     On Error GoTo ErrorHandler
    7.    
    8.     lonSize = FileLen(FilePath)
    9.    
    10.     Open FilePath For Binary Access Read As #lonFF
    11.        
    12.         ReDim bytData(1 To PacketSize) As Byte
    13.        
    14.         Do Until (lonSize - lonCurByte) < PacketSize
    15.             Get #lonFF, lonCurByte + 1, bytData()
    16.             lonCurByte = lonCurByte + PacketSize
    17.             SocketObject.SendData bytData()
    18.             DoEvents
    19.         Loop
    20.        
    21.         lonPrevSize = lonSize - lonCurByte
    22.        
    23.         If lonPrevSize > 0 Then
    24.             ReDim bytData(1 To lonPrevSize) As Byte
    25.             Get #lonFF, lonCurByte + 1, bytData()
    26.             lonCurByte = lonCurByte + lonPrevSize
    27.             SocketObject.SendData bytData()
    28.         End If
    29.    
    30.     Close #lonFF
    31.     Exit Sub
    32.    
    33. ErrorHandler:
    34.         Debug.Print "Send File Error"
    35.         Debug.Print "---------------"
    36.         Debug.Print "Number:      " & Err.Number
    37.         Debug.Print "Description: " & Err.Description
    38.         Debug.Print "File:        " & FilePath
    39.    
    40. End Sub

    so does this function only send the contents of the file?? not the actual file itself?

    how can i end up viewing the file then if its a .png .html etc?
    i want to be able to transfer files (rather than just file contents)between myself and another user thorugh a winsock connection
    Last edited by Pouncer; Dec 3rd, 2005 at 05:51 PM.

  2. #2
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: question on this function i found

    You send files in chunks, usaully 4096 or so bytes at a time(multiples of 1028 bytes). Winsock can't really deal with sending large amounts ot data at once. Would probably be ok sending a whole file over say a home LAN, but over the net your most likely going to end up with a corrupt file at the other end. So the client takes a chunk of the file (GET #1,,strChunk) and sends it to the server. The server then starts to reconstruct the file, chunk by chunk, using the PUT command (PUT #1,strChunk)... etc. The client sends the next chunk, server add this to the previous etc.. until all the file is sent. The do Loop ensures this.

    So you are sending the actual file and not the contents, your opening it as Binary.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: question on this function i found

    so this wont work for .png or other files? only.txt files?

    when the client sends the file to the server, do i have to put some code on the server winsock too?

    i want it to store the sent file in documents

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