|
-
Dec 3rd, 2005, 05:32 PM
#1
Thread Starter
Frenzied Member
question on this function i found
VB Code:
Public Sub SendFile(SocketObject As Variant, ByVal FilePath As String, ByVal PacketSize As Long)
Dim lonFF As Long, bytData() As Byte
Dim lonCurByte As Long, lonSize As Long
Dim lonPrevSize As Long
On Error GoTo ErrorHandler
lonSize = FileLen(FilePath)
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
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
SocketObject.SendData bytData()
End If
Close #lonFF
Exit Sub
ErrorHandler:
Debug.Print "Send File Error"
Debug.Print "---------------"
Debug.Print "Number: " & Err.Number
Debug.Print "Description: " & Err.Description
Debug.Print "File: " & FilePath
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.
-
Dec 3rd, 2005, 06:12 PM
#2
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.
Last edited by Jmacp; Dec 3rd, 2005 at 06:20 PM.
-
Dec 3rd, 2005, 06:15 PM
#3
Thread Starter
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|