Click to See Complete Forum and Search --> : Winsock - Advanced


ekratzer
December 16th, 1999, 02:16 PM
Hello All!!

I need to send objects of VB user defined types over a VB winsock. Is there a
simple way to do this? According to VB documentation, the winsock can only send
strings and binary arrays.

I have a zillion questions now :)

-Would writing a c++ DLL to pack and unpack these objects into a byte array work?
-What about strings and variants that do not have a fixed length?
-What does a VB user defined object look like in memory? Is it laid out continuous?
-How do you specify how many bytes you would like to receive before the winsock data_arrival event goes off?

Any suggestions would be very much apreciated.

czimmerman
December 16th, 1999, 03:13 PM
To send UDTs and objects via Winsock, I usually just break apart the object/UDT into it's constitiuent parts on the client end, send it, and reconstruct it on the receiving end. Usually, this requires using Headers and delimiters, which I define as constants.

<< What about strings and variants that do not have a fixed length?>>

It doesn't matter what their length if, you send it via SendData, and DataArrival will get it via GetData. You can specify how much data you would like to receive in the optional MaxLen argument of GetData. If not specified, all the data will be retrieved.

<< How do you specify how many bytes you would like to receive before the winsock data_arrival event goes off? >>

Data_Arrival goes off when new data is available. As I stated above, you can specify how much data you would like to receive from the GetData call, but you cannot control when DataArrival is fired.

Charlie Zimmerman
http://www.freevbcode.com

ekratzer
December 16th, 1999, 03:37 PM
Thanks for responding.

I have already tried the method you described, which works absolutley fine.
But my application has grown too complex. I need to send at least 10KBytes
of data to the client at regular intervals (between 1 and 10 second updates).
8 Kbytes of the data is binary waveform data, and the other 2KB is a large
user defined type with many many many elements. The client sever application
lets you remotely view a realtime acquisition system, so data must arrive in
order (time-wise). I was sending element(s) individually with delimitters, but
since the client needs to acknowledge all of these things in order, the latency
of sending 20-50 of these small messages becomes tremendous!! (especially over
dial up connections). I need to send an entire update at once, and respond
once so that network latency is not an issue. Do you know of any alternative
methods?



**********************
To send UDTs and objects via Winsock, I usually just break apart the object/UDT into it's constitiuent parts on the client end, send it, and reconstruct it on the receiving end. Usually, this requires using Headers and delimiters, which I define as constants.

<< What about strings and variants that do not have a fixed length?>>

It doesn't matter what their length if, you send it via SendData, and DataArrival will get it via GetData. You can specify how much data you would like to receive in the optional MaxLen argument of GetData. If not specified, all the data will be retrieved.

<< How do you specify how many bytes you would like to receive before the winsock data_arrival event goes off? >>

Data_Arrival goes off when new data is available. As I stated above, you can specify how much data you would like to receive from the GetData call, but you cannot control when DataArrival is fired.

czimmerman
December 16th, 1999, 04:28 PM
I think you are referring to the problem whereby if you try to send a lot of data at once, it won't arrive all in one shot; i.e., it will be divided up into pieces by the TCP protocol. This is probably why you are sending pieces individually, correct?

If so, you still should be sending everything in one message. The whole message may not arrive at once, but TCP guarantees it will arrive in the correct order. Then you need to assemble the message itself on the server end, and then you need to re-assemble your data/UDT based on your delimiters.

If I am understanding your problem correctly, you can have a class I developed for re-assembling large winsock messages. It works by prefacing each message with the length of the whole message before it is sent, then buffering the response on the server side until that message length is reached. If you want this class, give me you e-mail addreses and I will e-mail it to you.

Charlie Zimmerman
http://www.freevbcode.com