Solved

multiple sockets

Posted on 2000-05-03
7
237 Views
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!!!
0
Comment
Question by:GoofyJoe99
7 Comments
 
LVL 28

Expert Comment

by:AzraSound
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:

http://www1.experts-exchange.com/bin/ShowQ?MBL=on&qid=10336651&anchor=2767554#2767554


0
 
LVL 10

Accepted Solution

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

http://homepage.eircom.net/~carafa/TEMP/AWXB.zip

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
solution.
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.

Solution:
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
AWXB01Thread.dll

Finally...
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

Pino


0
 
LVL 10

Expert Comment

by:smegghead
ID: 2773299
Stunned silence....
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 10

Expert Comment

by:caraf_g
ID: 2773371
hehe
0
 
LVL 5

Expert Comment

by:KDivad
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...
0
 
LVL 10

Expert Comment

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

<blush>
0
 

Author Comment

by:GoofyJoe99
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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now