Solved

How to implement simultaneous processes?

Posted on 2000-02-20
7
366 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

827 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