?
Solved

multiple sockets

Posted on 2000-05-03
7
Medium Priority
?
246 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
[X]
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
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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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 Month13 days, 21 hours left to enroll

800 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