Help with VB6 Winsock problem - data arrives in segments 
Author Message
 Help with VB6 Winsock problem - data arrives in segments

I need help/advice with a winsock problem.  Here's what I'm using:

Visual Basic 6 (SP5)
VB Winsock control
Windows 2000 Pro
TCP protocol

I'm creating a client application that communicates with a host on a
VAX/VMS system.  It's a real-time application that transfer large
amounts of data (up to 32K per message) from the VAX to the client
every second.

Here's the problem.  In VB, there is a data arrival event that is
supposed to fire when data arrives.  However, it fires when less than
the entire message has arrived.  In fact, it seems to fire when as
little as 512 bytes have arrived.  The amount of data varies.  In
fact, if I put a break point in the data arrival event (so it sits
there for a second with nothing to do), it seems to retrieve a much
larger segment of the message at next firing (e.g., 8K).

Fortunately, the first thing the VAX sends in each message is the
length of the entire message.  So I simply rebuild the entire message
at the VB6 end before processing it.  But I shouldn't have to do this,
right?

Should I be using a different winsock?  Can't winsock handle large
messages without segmentation?

Bryce May
Sr. Developer
MSS, Michgian



Tue, 14 Dec 2004 20:00:42 GMT  
 Help with VB6 Winsock problem - data arrives in segments

Quote:
> Here's the problem.  In VB, there is a data arrival event that is
> supposed to fire when data arrives.  However, it fires when less than
> the entire message has arrived.  In fact, it seems to fire when as
> little as 512 bytes have arrived.  The amount of data varies.  In
> fact, if I put a break point in the data arrival event (so it sits
> there for a second with nothing to do), it seems to retrieve a much
> larger segment of the message at next firing (e.g., 8K).

> Fortunately, the first thing the VAX sends in each message is the
> length of the entire message.  So I simply rebuild the entire message
> at the VB6 end before processing it.  But I shouldn't have to do this,
> right?

> Should I be using a different winsock?  Can't winsock handle large
> messages without segmentation?

Bryce,

A TCP socket presents a stream interface. It knows nothing of your
application's concept of messages. You always have to handle the work
involved in chunking the incoming byte stream into messages yourself.

If you happen to be sending small messages then you may be fooled into
thinking that each data ready event will give you a complete, distinct,
message, but this is not the case. You always have to process the byte
stream yourself and break it into messages depending on how your protocol
defines the messages.

The reason that you're seeing more data arrive when you have a breakpoint
set is that the data is arriving whilst you're sitting in the breakpoint so
that when you run again there is more data available for the next data
arrival event.

--
Len Holgate
http://www.jetbyte.com
The right code, right now.
Contract Programming and Consulting Services.



Tue, 14 Dec 2004 20:08:50 GMT  
 Help with VB6 Winsock problem - data arrives in segments

Quote:
>The reason that you're seeing more data arrive when you have a breakpoint
>set is that the data is arriving whilst you're sitting in the breakpoint so
>that when you run again there is more data available for the next data
>arrival event.

Thanks for the information, Len.  BTW, I checked out your web site and
found it to be very good, too.

I modified my code to re-assemble my messages and all works fine.  Now
I'm wondering if I had chosen the Winsock API rather than the VB
Winsock Control, I might have better efficiency and more control over
things . . . like timeouts, buffer sizes, and maybe better control
over how much we want to receive with each read (recv())?

So now I'm wondering, will learning how to use the Winsock API (rather
than the control) be worth while for this project?



Fri, 17 Dec 2004 03:03:42 GMT  
 Help with VB6 Winsock problem - data arrives in segments
From what you've said, I think the winsock control should be fine.  Is there
anything you need it to do, but can't?  If you're after efficiency, use C++
8-)


Quote:
> >The reason that you're seeing more data arrive when you have a breakpoint
> >set is that the data is arriving whilst you're sitting in the breakpoint
so
> >that when you run again there is more data available for the next data
> >arrival event.

> Thanks for the information, Len.  BTW, I checked out your web site and
> found it to be very good, too.

> I modified my code to re-assemble my messages and all works fine.  Now
> I'm wondering if I had chosen the Winsock API rather than the VB
> Winsock Control, I might have better efficiency and more control over
> things . . . like timeouts, buffer sizes, and maybe better control
> over how much we want to receive with each read (recv())?

> So now I'm wondering, will learning how to use the Winsock API (rather
> than the control) be worth while for this project?



Fri, 17 Dec 2004 10:00:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Help with VB6 Winsock problem - data arrives in segments

2. vb6-winsock-data receive problem

3. VB6: Winsock senddata problem - help!

4. 64K Data Segment Limitation in V5.0

5. VB6 & Winsock - Get incomming data

6. Odd problem with code segment

7. how to send notification email when new email arrives (help needed, please)

8. .NET Socket vs VB6 Winsock problem!

9. VB6 Winsock Problem

10. Winsock problem: SendComplete event missing in VB6

11. VB6 Winsock UDP server port binding problem

12. Winsock Control Problem in VB6

 

 
Powered by phpBB® Forum Software