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


multiple sockets

Posted on 2000-05-03
Medium Priority
Last Modified: 2010-05-18
Im trying to open multiple sockets and have them all do something at the same time. I know threads is not gonna happen but is there a way to do multiple sockets. I want to open one socket, give it a function, then open another and give it a function before the previous is finished. Help!!!
Question by:GoofyJoe99
LVL 28

Expert Comment

ID: 2772295
without creating a separate thread or process for each one, your cpu will only perform the tasks called by your program synchronously.  since your program is, in essence, a single process, if you want your cpu to incorporate separate threads into its pipelining scheme then it must see separate threads/processes.  a similar discussion is being carried on at this question location:


LVL 10

Accepted Solution

caraf_g earned 400 total points
ID: 2772512
Threading without rocket science.


Explanation / order of compilation
AWXB02MSG.exe - (ActiveX.exe, one thread for all objects) Messaging
application that will take care of sending messages between spawned threads
and the main application.
AWXB01Thread.dll - The code that will be run in each separate thread
AWXB04Starter.exe - (ActiveX.exe, one thread per object) Application that
will take care of creating each new thread.
AWXB03Test.exe - Standard exe. Main application / test bed.

Where did it come from...

1 - I had to write a multi threading application. This was a problem, as
VB(6) does not support free threading. It does however support some forms of
threading, and I had to investigate these.

2 - The problem with VB function calls is that all of them work
synchronously. As a result, you cannot, in Native VB, create the situation
where process A initiates Process B, then forgets about it, and both
processes continue in parallel. At least, not if you want to avoid shelling
out separate .exes. Shelling is *WAY* too slow. I wanted an ActiveX
As a result, I had to investigate APIs. CreateThread is one option, but it's
too quirky and too much like rocket science. Basically you cannot guarantee
that a program using CreateThread will not bomb out with GPFs and similar
horrible errors unless you've got a brain the size of a planet.... I quickly
abandoned that idea. So the other solution is to use a Timer. I could have
used a VB timer, but the API timer is a bit more elegant and it does not
require you to introduce a dummy form.

3 DLLs are not usable for multi-threading. Even if you take an apartment
threaded idea, each apartment will run in the same thread as the calling
process. Again, there are weird and wonderful API solutions to this, but
again it requires a brain the size of a planet... So forget that. I then
looked at ActiveX .exes for the solution. They worked.

4 This is where I ran into a problem with the threading models supported in
VB, especially with regards to global data (variables). Basically, there are
two threading models in VB:
a - Thread pool. You can specify as many threads as you wish, but the
problem is that every object that is created is assigned a thread
"randomly". For sharing global data that is useless. So the only viable
option there is to have 1 thread. Now you're OK. Every object that is
created uses the *same* global data so it can be shared between the objects.
But... *BANG* goes your multi-threading, because *ALL* objects run in the
*SAME* thread....
b - Thread per object. Ideal for multi threading. Every object you create
runs in its own thread.... but, now you can't share global data. If you have
a simple application, this is no problem, as you can code everything into a
single class, but if your application gets any more complex, you'll need new
classes, and your model will fall apart...

So here's a dilemma.... There are two viable threading models available in
my ActiveX .exe, but both have insurmountable problems. One model is useless
wrt global data, the other wrt multi threading.

5 The ActiveX.exe will only contain a SINGLE object. This object's sole
function will be to cater for the multi-threading. Once that is achieved,
we'll hand over execution to an Apartment Threaded DLL, which will then take
care of any other classes and objects that need to be created, and it will
ensure that all these new objects are all created in the *SAME* thread.

The activeX.exe is AWXB04Starter.exe , and the Apartment Threaded DLL is

As long as execution remains synchronous, it is very easy for a called
function to report back to a calling function. It merely needs to switch off
error handling, and raise a user-defined error. The calling function can
than handle this "error" and act appropriately.

But in asynchronous execution, that won't work. In actual fact, if you raise
an error in the asynchronous bit (that which is called from the TimerProc)
your ActiveX.exe will crash.

So how will the threads report back information to the calling application?

6 Introduce a Thread Pool ActiveX.exe (1 thread) that will take care of
handling messages between the thread(s) and the calling application.
This ActiveX.exe is AWXB02MSG.exe

Hope this helps


LVL 10

Expert Comment

ID: 2773299
Stunned silence....
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 10

Expert Comment

ID: 2773371

Expert Comment

ID: 2773519
<<Stunned silence...>>
I must agree...
Sounds like rocket science until you realize that it means someone else has figured it out and has made a template we little people could build from. And for that:

I hunbly bow to thee, caraf...
LVL 10

Expert Comment

ID: 2773578
Oh nooooo, you've got me all embarrassed now


Author Comment

ID: 2778223
Cool thanks!!!! Im not a rocket scientist but Im gonna try that I hope i understood all that you said. Im gettin to work

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

578 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