Solved

OnRecieve Help

Posted on 2003-11-25
10
192 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 88
Detect CR LF to each line 12 160
if loop in java 3 141
Annoying "thing" blocks my view 4 100
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

773 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