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

x
?
Solved

How to implement simultaneous processes?

Posted on 2000-02-20
7
Medium Priority
?
385 Views
Last Modified: 2010-04-15
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?
0
Comment
Question by:mych
[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 86

Expert Comment

by:jkr
ID: 2539688
What OS are you targetting?
0
 
LVL 3

Expert Comment

by:arnond
ID: 2539768
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
 
LVL 86

Expert Comment

by:jkr
ID: 2539919
'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
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!

 
LVL 3

Expert Comment

by:arnond
ID: 2540041
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
 
LVL 86

Expert Comment

by:jkr
ID: 2540594
>>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
 

Author Comment

by:mych
ID: 2541079
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
 
LVL 3

Accepted Solution

by:
ufolk123 earned 400 total points
ID: 2541124
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

Featured Post

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.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

636 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