multiple sockets

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!!!
Who is Participating?
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


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:

Stunned silence....
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

<<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...
Oh nooooo, you've got me all embarrassed now

GoofyJoe99Author Commented:
Cool thanks!!!! Im not a rocket scientist but Im gonna try that I hope i understood all that you said. Im gettin to work
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.

All Courses

From novice to tech pro — start learning today.