Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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'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.

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

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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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

598 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