Yes. And probably the easiest way is to investigate the fact that StdPicture is persistable (It is certainly the technique I use to quickly and easily send picture objects from one computer to another via winsock without having to write any protocol handling of my own)
Wow! That's exactly what I'm (desperately) looking for! To send a picture between 2 computers using winsock.
But how do yuo manage that? I mean it's not working just to:
Private iPicture as StdPicture
...
WS1.SendData iPicture
Thanks very much, strongm!
I'll trie it! Looks simple and it seems to be just what I was looking for: a simple solution to do the job.
Before this I was traying with DIB and, oh ... it was a pain 'cause I'm not that familiar wit this immage processing techniques.
Thanks again!
Bad news:
I've tried your code from Thread222-557000, but it doesn't work. To be more exact, at line "pb.Contents = buffer" from event procedure "Winsock2_DataArrival" a get the error message: "Invalid procedure call or argument."
Why is that? What I am missing here?
The code is an illustration rather than a rigorous solution. Your error is being caused by the fact that the initial data arrival event does not actually transfer the entire propertybag. Indeed, it may take several data arrivals to fully transfer it.
And a possible solution would be something like that:
On "SendComplete" event of the sender to send another message to the client, let's say a vbCrlf; while on the client side, before reading into pb.Contents:
Winsock2.GetData buffer, , MyVar
if not MyVar = vbcrlf then
pb.Contents = buffer
else
Set Picture2.Picture = pb.ReadProperty("SentStdPicture", 0)
endif
I think that should work... I'll trie that and let you all know.
Thanks.
Private Sub Command1_Click()
Dim pb As PropertyBag
Set pb = New PropertyBag
pb.WriteProperty "SentStdPicture", Image1.Picture, 0
Winsock1.SendData pb.Contents
End Sub
Private Sub Form_Load()
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
End Sub
On the client side:
Dim pb As PropertyBag
Dim Buffer() As Byte, Storage() As Byte
Dim Nr As Integer
Private Sub Command1_Click()
Image2.Picture = LoadPicture
End Sub
Private Sub Form_Load()
Winsock2.Connect
ReDim Preserve Storage(0)
End Sub
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Set pb = New PropertyBag
Winsock2.GetData Buffer, vbByte + vbArray, bytesTotal
OldUBoundStorage = IIf(UBound(Storage) = 0, 0, UBound(Storage))
ReDim Preserve Storage(UBound(Storage) + UBound(Buffer) + 1)
For x = 0 To UBound(Buffer)
Storage(x + OldUBoundStorage) = Buffer(x)
Next
On Error GoTo e:
pb.Contents = Storage
Set Image2.Picture = pb.ReadProperty("SentStdPicture", 0)
ReDim Storage(0)
e:
End Sub
strongm, thanks for the initial hint!
Here's a star for you. Well, I should probably award one to myself to!
1.) Disregard "OldUBoundStorage = IIf(UBound(Storage) = 0, 0, UBound(Storage))" It should be just "OldUBoundStorage = IIf(UBound(Storage)"
2.) Disregard "Dim Nr As Integer" It is never used...
3.) Disregard
"Private Sub Command1_Click()
Image2.Picture = LoadPicture
End Sub" It is of no use for the subject.
4.) Does anyone know how to concatenate 2 byte arrays faster then I did?
Thankc.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.