Thursday, 8 August 2013

VB6 - Send File (Picture) using Winsock

VB6 - Send File (Picture) using Winsock

I tried to send several pictures (JPEG and BIMP) using Winsock.
Server send bytes and client receive them without any problems.
But when i want to use my picture (e.g. Load it into a PictureBox) it says
"Invalid Picture" and i think that my project doesn't send some of bytes
or maybe problem is in the last pocket i try to send. Here is my codes:
sFilePath = (a JPEG valid picture (size: about 500KB))


Server Side:

Public Sub SndFile(FilePath As String)
sFilePath = FilePath
countn = 1
lenfile = FileLen(sFilePath)
Timer2.Enabled = True
End Sub
Private Sub Timer2_Timer()
sData = Space(4000)
Open sFilePath For Binary As #98
Get #98, countn, sData
If lenfile <= 4000 Then
Winsock1.SendData "DDDD" & Trim(sData)
Close #98
Timer2.Enabled = False
End If
If countn < lenfile Then
If countn + 4000 > lenfile Then
Winsock1.SendData "DDDD" & Trim(sData)
Close #98
Timer2.Enabled = False
Else
Winsock1.SendData "DADD" & sData
Close #98
End If
End If
countn = countn + 4000
End Sub
Client Side:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Winsock1.GetData dr, vbString
Select Case Left(dr, 4)
Case "DDDD"
fil22 = fil22 & Right(dr, Len(dr) - 4)
Open "Downloading File Address" For Binary As #23
Put #23, 1, fil22
Close #23
fil22 = ""
MsgBox "Download Completed! Go: " & dr, vbInformation, ""
Case "DADD"
fil22 = fil22 & Right(dr, Len(dr) - 4)
End Select
End Sub

No comments:

Post a Comment