send image with winsock visual basic 6

posted by programmervb on 2009-07-11 19:33:02
hello, I have a problem I cannot send an image with winsock: (I am creating a program client/server where the server sends an image to the client and must show it in picturebox, but the client receives a piece of the image and only shows error in run time of which she cannot insert the image in picturebox.
code server:
public function SendImage()
	Dim image as string
 
	open "image.jpg" for binary as #1
		get #1,,image
	close #1
 
	doevents
 
	if winsock1.state = sckConnected then
 
		winsock1.senddata image
	end if
end function
code client:
 
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
 
	Dim image as string
 
	winsock1.getdata image
 
	open "image.jpg" for binary as #1
 
		put #1,,image
 
	close #1
 
	doevents	
 
	picture1.picture = loadpicture("image.jpg")
 
End Sub
iup85
0
Can you see how many bytes you received?
4 answers - 6 questions
  Positive        Negative

programmervb
0
Posted by iup85:
Can you see how many bytes you received?

I do not understand very well your question.
my english not is very good. I am from argentina
3 answers - 1 questions
  Positive        Negative

iup85
0
Posted by programmervb:
I do not understand very well your question.
my english not is very good. I am from argentina

You wrote: "...client receives a piece of the image..." can you tell me, how many bytes does this piece have?
4 answers - 6 questions
  Positive        Negative

programmervb
0
Posted by iup85:
You wrote: "...client receives a piece of the image..." can you tell me, how many bytes does this piece have?

2 bytes but modify now it and receive 0 bytes: (
they can publish a code of example of how doing it?
3 answers - 1 questions
  Positive        Negative

dail avatar
dail
12
To send a file using Visual Basic 6 with the winsock, take a look at:
 
Private Const chunk = 8192
Dim filename As String  'path of the image
Dim data
Open filename For Binary As #1
Do While Not EOF(1)
    data = Input(chunk, #1)
    winsock1.SenData data
    DoEvents
Loop
close #1
 
in the data_arrival event, "append" each chunk to the file.
 
Open filename For Append As #1
 
then... load the file on the PictureBox component.
Attention: you should send a "command" (from your SendImage function) to know when the transfer is complete.
49 answers - 0 questions
  Positive        Negative

programmervb
0
Posted by dail:
To send a file using Visual Basic 6 with the winsock, take a look at:
 
Private Const chunk = 8192
Dim filename As String  'path of the image
Dim data
Open filename For Binary As #1
Do While Not EOF(1)
    data = Input(chunk, #1)
    winsock1.SenData data
    DoEvents
Loop
close #1
 
in the data_arrival event, "append" each chunk to the file.
 
Open filename For Append As #1
 
then... load the file on the PictureBox component.
Attention: you should send a "command" (from your SendImage function) to know when the transfer is complete.

Now receipt up to 4 bytes of the image :( and it does not send but :S
3 answers - 1 questions
  Positive        Negative



Answer the question



Top Users
  • dail (12)
  • livin52 (3)
  • camu (3)
  • softweb (2)
  • Nadine (1)
  • Josware (1)
  • lfelipecr (1)
  • gregoriohc (1)
  • Mitu (1)
  • ryan714 (1)