Solved

How to implement simultaneous processes?

Posted on 2000-02-20
7
340 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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…
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.
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.

708 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

18 Experts available now in Live!

Get 1:1 Help Now