Solved

OnRecieve Help

Posted on 2003-11-25
10
194 Views
Last Modified: 2013-11-20
I have a socket that typically recieves messages at faily low rates. However, there are times when it will be reading messages as fast as possible do to the request for a list command. The problem with this is that it seems to lock up the application so that no other messages are processed. How can I make it so that the application will still process OnRecieve messages fast, but still catch all mouse clicks, window resizing, etc.?
0
Comment
Question by:SGyves
[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
  • 5
  • 3
  • 2
10 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 500 total points
ID: 9822407
For that you have to limit the amount of data in one receive to minimun and apply a loop.

and in that loop, place this code

         MSG msg;

         while ( ::PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE) )
         {
              ::TranslateMessage(&msg);
              ::DispatchMessage(&msg);
         }


Good Luck
0
 

Author Comment

by:SGyves
ID: 9825823
I tried that...but I can't even see the mouse in the window area of my application when I add this code to OnRecieve. Any other advice rosh?
0
 
LVL 4

Expert Comment

by:inox
ID: 9830934

the problem you have may be that the processing of the data received is slower than the receiving. In that case "OnReceive" messages are stacked, and then the messagedispatching also does not help. Can you ommit the "processing of the data received" for test reasons to see if UI works better? (so the right steps to be made later)
0
Independent Software Vendors: 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!

 

Author Comment

by:SGyves
ID: 9832480
Yes...of course if I omitt the prcessing of data...it solves it. It is only under heavy recieve conditions that this happens.
0
 
LVL 4

Expert Comment

by:inox
ID: 9837006

well this was expected (but it could be possible that the application is busy doing other things also) so the load comes from telegramreceiving and processing
unfortunately now things may become a bit complicated serveral questions are meaningful to find the best way
- can the telegram data processing be done delayed or must it be 'just in time'
- if jit can the telegram data processing split in jit part and delayable part
- how is the frequecy evenly spread or batch-wise

I think the best way to perform heavy socket traffic is:
- do it in a seperate thead
- prefer Windows Sockets library to MFC
- split job for telegramprocessing in an immediate excecution and queue datas in a collection (list) for later processing (idle-time)
depending on needs this may be simplified
0
 

Author Comment

by:SGyves
ID: 9855514
Well it would seem to be fine to hold all other operations and to make recieving a low priority. Meaning...as long as there is nothing from the UI to process....go ahead and recieve. It will suck if I have to move it back into its own thread. That is the way i had it before...and that spawned a whole other set of problems.
0
 
LVL 4

Expert Comment

by:inox
ID: 9858617

I recommend to do communication in a seperate thread using the socket api.
I understand that you don't want to do this but you won't have great influence on how messages (receiving and UI) are queued and processed in Messageloop.
Maybe it helps if you create a thread in the OnReceive-handler and do just dataprocessing there.
0
 

Author Comment

by:SGyves
ID: 9897892
So there is no way for my program to make sure it processes UI messages while all of this reciveing is going on? You know, I have had this socket in and out of a thread a number of times. Each method posed new problems that no one can seem to solve. Let me explain the situation a little better. The only instance that creates an overload problem is when someone requests a list of channels from the server...and that server has hundreds of channels to send. Otherwise...the program does okay. Why is it that the mouse cursor can not leave the window when we put a message pump inside of OnRecieve???
0
 

Author Comment

by:SGyves
ID: 9897935
Thank you rosh for the solution. It didn't work at first when I placed the message pump right in the OnRecieve() functions. But all was good when I moved the data processing to a separate function and put the message pump in that function. Simple...easy....no more headache.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9901662
Thankx
Sorry for the delay, I was not here

Rosh :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
List out all word 7 359
has22 challenge 11 111
Sed question 2 139
"Black Box" Testing of Control System Software 2 126
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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