Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

MSWINSCK.OCX sending data accross multiple controls

Posted on 2004-11-03
12
Medium Priority
?
389 Views
Last Modified: 2013-12-26
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)
0
Comment
Question by:o0JoeCool0o
  • 7
  • 5
12 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12485458
Are you using TCP or UDP?

~IM
0
 
LVL 4

Author Comment

by:o0JoeCool0o
ID: 12485658
TCP
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12486298
>> 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:o0JoeCool0o
ID: 12486396
>>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
 
LVL 4

Author Comment

by:o0JoeCool0o
ID: 12486686
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
 
LVL 4

Author Comment

by:o0JoeCool0o
ID: 12487292
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
 
LVL 4

Author Comment

by:o0JoeCool0o
ID: 12488787
increasing points really need to a way to make this go faster
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12489553
You should be able to send about 4096 bytes at a time without them getting fragmented.

~IM
0
 
LVL 4

Author Comment

by:o0JoeCool0o
ID: 12494650
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12497104
Ah...ok.  You are sending one file to the same person over 300 connections?

~IM
0
 
LVL 4

Author Comment

by:o0JoeCool0o
ID: 12499824
correct
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 12505683
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question