MSWINSCK.OCX sending data accross multiple controls

I am trying to send data accross 300 open ports. so I load 300 winsock controls in a control array. then I send a file, I send each byte on a random port, this works alright if I put a pause in the loop if I send it all at once most of the data is jsut dropped and never arrives. with the pause it is very slow however like 100 bytes per second locally! Now going over the net is the biggest problem as some bytes arrive before others isntead of in the sequence they were sent. I guess with lag and what not the third byte will arrive before the 1st byte  etc.  Is there a way I can get the data to arrive sequentially without having to send a whole byte for each byte sent (ackknowlegement)
LVL 4
o0JoeCool0oAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike TomlinsonMiddle School Assistant TeacherCommented:
Are you using TCP or UDP?

~IM
0
o0JoeCool0oAuthor Commented:
TCP
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
>> Now going over the net is the biggest problem as some bytes arrive before others isntead of in the sequence they were sent.

That should be impossible with TCP.

For each control, the bytes will arrive in the correct order.  It is possible that some byte streams will arrive before others and there is nothing you can do about that.  The order of the bytes will be correct however.

>> Is there a way I can get the data to arrive sequentially without having to send a whole byte for each byte sent (ackknowlegement)

You do actually get an ack signal built into the winsock control in the form of an event.  Each time you send data, you will receive a SendComplete event when the data has been successfully sent.

    Private Sub Winsock1_SendComplete(Index As Integer)

    End Sub

What you can do is send the data on the first port and then wait for the event.  When it arrives, send that data to the next port and so on until you have looped through all of the ports you need to send to.  Then you can move to the next byte in the stream.  One problem with this approach is that if one connection hangs, the others will also hang since you are waiting for the SendComplete() event.

Alternatively, you could track where in the file each connection is by using the Tag property of each control or using a seperate array.  Then you can seek in the file to the correct position and read the next couple bytes to send.  The problem with this approach is that you must essentially do this as a complete operation like in a synchronzied data access call when using multiple threads.  This can lead to some streams getting starved while they wait their turn to access the file.

At any rate, VB6 is not a good choice for streaming a file over 300 connections at once since it is not multithreaded.  I once wrote a simple application that attempted to send two files at once using a winsock control array and what I found was that the stream that was started first seemed to dominate the application while the second stream only trickled along.

Why do you need to stream to 300 ports at once?  Is it possible to send the file to each destination seperately?

~IM
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

o0JoeCool0oAuthor Commented:
>>That should be impossible with TCP.

>>For each control, the bytes will arrive in the correct order.  It is possible that some byte streams will arrive before others and there is >>nothing you can do about that.  The order of the bytes will be correct however

I thought it would be but in sending a text file u can clearly see that this is the case why else would it work flawlessly when sending it to myself locally through 127.0.0.1

problem is i can only send one byte on one port at a time, i will try the sendcomplete event and see if that works
0
o0JoeCool0oAuthor Commented:
the seondcomplete works, however its still very slow, it is much faster now though went from 100 bytes per second to 1K per second. But 1k per second locally is hardly anything to cheer about.
The only thing i can think of to speed it up would be to send duplicate bytes  as one bytes so read ahead if there are 10 bytes the same send one byte with the value of 10 so im not sending all the bytes through... Any more ideas? Im sure this would work better written in C or something unfortunatly i do not know C, I could try using VB.net hwoever... and see if it increases the speed

0
o0JoeCool0oAuthor Commented:
I converted it to vb.net and its back down to 100 bytes per second, so obviously VB6 is alot faster then .net for winsock applications...
But still need a way to increase this from 1k per second to like a meg per second, locally it should only be limited by how fast he data can be written to the hard drive, maybe a little slower but over the net it should be an average file transfer application.
0
o0JoeCool0oAuthor Commented:
increasing points really need to a way to make this go faster
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
You should be able to send about 4096 bytes at a time without them getting fragmented.

~IM
0
o0JoeCool0oAuthor Commented:
I think you are misunderstanding, byte 1 is send on port 1 byte 2 sent on port 2 byte 3 send on port 3 etc
so because there on separate connections/Ports/Streams byte 3 will arrive before byte 2 if it lags

even using the send complete event, I wait for the sendcomplete event to occur before sending the next byte on the next port but somehow its writing the recieved bytes in the wrong order all jumbled.

I am going ot have to send a byte back to the sender side as an ACK it appears thatd be the only way
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Ah...ok.  You are sending one file to the same person over 300 connections?

~IM
0
o0JoeCool0oAuthor Commented:
correct
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Sending one byte at a time on each stream will definitely slow the process down.

Typically in systems that use multiple connections, each connection is actually streaming a different block of the file.  Each stream will arrive in the correct order for that block, and is saved to its own temporary file.  When one block is complete, that connection can be reused for the next available block.  When all blocks have been received, the file is reassembled from all the pieces in the correct order.  You can track the pieces using code and some kind of structure or simply name the temp files so you can determine the order from the names.  I'm not sure how reading from different places in the file will affect speed though since the file pointer will have to be moved to the different postions in the blocks being sent as it streams.  Maybe you could start off by splitting the file into seperate pieces before sending it so that each temp file can maintain its own file pointer without having to move back and forth.

I haven't done any testing on this, but 300 connections seems a bit much.  Have you done any benchmarking with other apps to see if there is an "optimum" number of connections?  I have seen other applications using three, four or five connections at once but never any that use connections in the hundreds!

~IM
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.