Solved

OnRecieve Help

Posted on 2003-11-25
10
190 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 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
 

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

746 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

11 Experts available now in Live!

Get 1:1 Help Now