Solved

How to implement simultaneous processes?

Posted on 2000-02-20
7
353 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
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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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 100 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

895 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

16 Experts available now in Live!

Get 1:1 Help Now