• C

How to implement simultaneous processes?

I have the procedural code to create a socket, connect to a server, send packets, and receive packets. However, what I would like to do is to send packets periodically at a fixed rate, and at the same time, receive packets whcih may not arrive synchronously with the packets that I send. How can I implement these 2 processes simultaneously?
mychAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ufolk123Connect With a Mentor Commented:
You can use the Async I/O options avaible by microsoft windows.
In this you can register whatever sockets events you want to handle asynchronously with windows.Whenever data comes , windows will automatically post you a message .You cam handle these messages in your window procedure.
You should see the documentation of following API.

int WSAAsyncSelect ( );

So you can register number of sockets with windows on which you require notification.

So you do the following.
put the code to handle the receiving data(async) in  window procedure.
Create a thread which will periodically send the messages to socket.
Now regsiter with windows that you are interested in FD_READ event on socket using the WSAAsyncSelect().
So your send thread will keep on sending data periodically while whenever data comes your window procedure will handle it.

Please get back for any futher doubts.
0
 
jkrCommented:
What OS are you targetting?
0
 
arnondCommented:
if you're using UNIX, you can use fork() to create a new process.
then you would probably use execve() or a similar function in (probably) the child process to start a different piece of code.

for more info, just ask.
Arnon David.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
jkrCommented:
'fork()' is a good suggestion for most UN*X OSs' - there are however some flavours of UN*X tht support threads, which would be my choice (as it would be for Win32) due to the reduced overhead...
0
 
arnondCommented:
yes, threads are good suggestions, but processes are simpler, both in creating and handling (don't need to syncronize processes as much as with threads)

Arnon.
0
 
jkrCommented:
>>don't need to syncronize processes as much as with
>>threads

Maybe - but the overhead produced by sharing per-process data beats this advantage... and if your OS doesn't use a copy-on-write strategy for duplicating the page tables (which most modern OSs do), the performance penalty for calling 'fork()' is incredible...
0
 
mychAuthor Commented:
I am using Windows, and doing the programming using Visual C++. I am actually not familiar with threads and processes. I have heard that something like this could be done using ActiveX. Can someone enlighten me?
0
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.