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
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 forCode: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
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!![]()
![]()
![]()
![]()





Reply With Quote