Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

OnRecieve Help

Posted on 2003-11-25
10
Medium Priority
?
197 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
  • 5
  • 3
  • 2
10 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 2000 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
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!

 

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

783 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