1

I am having trouble sending a propertybag over winsock. I have a client/server application that sends images through using a propertybag. I convert the propertybag into a byte array and try to send it over winsock and then when I convert the byte array back to a propertybag, it cant seem to read it. It looks like the data was corrupted when it was sent.

Client(sending propertybag)

Dim pb As PropertyBag
Dim byt() As Byte

Set pb = New PropertyBag

pb.WriteProperty "picc", Image1.Picture
byt = pb.Contents

Winsock1.SendData byt

Server(Receiving propertybag)

   Dim byt() As Byte
   Dim pb As PropertyBag

   Set pb = New PropertyBag

   Winsock1.GetData byt, vbByte

   pb.Contents = byt
   Image1.Picture = pb.ReadProperty("picc")

The error I received:

Run-time error '327':
Data value named 'picc' not found

When I try to do execute the code in a single program without winsock, it works just fine. The problem occurs when I send the byte array over winsock.

user2313602
  • 303
  • 4
  • 10
  • 1
    i would write both byte arrays (sent and received) to a file and compare the differences – Hrqls Mar 19 '14 at 09:57
  • One `SendData` call can't be reliably received via one `GetData` call. This is the "packet fallacy." You do not send data in user-defined "packets" but send stream fragments and receive stream fragments that are not the same length (and may be as small as 1 byte per data arrival event). TCP is not a datagram protocol. – Bob77 May 08 '14 at 06:20

1 Answers1

2

Most people also utilize the ADO stream object (add reference to Microsoft ActiveX Data Objects 2.5 or whatever version) by going to Project -> References.

Here is a working example you can download using a PropertyBag as well as the ADO stream object.

It's called PicturePicture.zip and written by a very Winsock & client/server-knowledgeable programmer.