|
if i hava a class
class a
{
int a;
CString str;
};
i want to write its object into a file and send that file through a network to different computer and i want to recive that object again if i have the same class there.
may i read the same object on network from a file?
any body can explain my idea into code like
how to write object into file ?
how to read object on the network (having same class there) from file ?
r00d0034@yahoo.com
|
|
|
|
|
See Serialize (u must thus derive ur class from CObject)
archives and using archives with sockets!
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Hi.
I am working on a simple client-based winsock Windows program. The program works well under the current software design. However, I discovered a huge resource problem.
The program support multiple simultaneous connections. I use the WSAAsyncSelect() I/O model to handle I/O. Everything works well. I implemented two worker threads. One thread sends data. The second thread receives data. WSAAsyncSelect() sends messages via Windows queue and update the program on FD_WRITE, FD_READ, etc. Again, the program works as planned.
I discover a huge resource problem. The program takes up all CPU resource as it makes more and more socket connnections. In other works, the program stalls if the user attemps to makes ten or more connections. CPU usage is 100%.
I re-read Network Programming for Microsoft Windows, Second Edition by Anthony Jones and Jim Ohmund. If I am not mistaken, you do not need workers thread for winsock if you use a non-blocking I/O such as WSAAsyncSelect().
I would like to know if there is a flaw in the program design. My thought right now is that this design will not work because of the worker threads. There is no way Windows can handle too many worker threads. However, let say I implemented WSASend() and WSARecv() solutions directly in the primary thread (main applications), I believe that will lock up Windows or at least the program. For example, if I implement a while loop that calls WSARecv() until it returns 0, that will lock up the program. Is that right?
Thanks,
Kuphryn
|
|
|
|
|
is there a while ( true ) loop somewhere??
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Yes, the problem definitely resulted from a while-loop. I am in the process of implementing a different approach to the algorithm.
I am debug a weird problem. For some reason, I cannot close an event handle. For example,
-----
HANDLE mEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
...
// This code crashes the program.
// Visual C++ debug says the error has something to do with an invalid
// handle.
::CloseHandle(mEvent);
-----
Kuphryn
|
|
|
|
|
Did you check that your handle was valid before trying to close it?
Signature space for rent. Apply by email to....
|
|
|
|
|
is the event being created??
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I think your best way of implementing this is to make new threads for each client connection.
Then, within the read thread, you can have a loop similar to this, which consumes negligible CPU time:-
WSAEVENT event;
WSANETWORKEVENTS netevents;
event = WSACreateEvent();
WSAEventSelect(s, event, FD_READ | FD_CLOSE);
DWORD result, lIdleTimeout;
lIdleTimeout=0
while (TRUE)
{
result = WSAWaitForMultipleEvents(1, &event, FALSE, 100, FALSE);
if (result == WSA_WAIT_TIMEOUT)
{
if (++lIdleTimeout > IDLE_CONNECTION_TIMEOUT)
{
closesocket(s);
return FALSE;
}
continue;
}
lIdleTimeout=0;
WSAEnumNetworkEvents(s, event, &netevents);
if (netevents.lNetworkEvents & FD_CLOSE) {
printf ("socket closed\n");
return TRUE;
}
if (netevents.lNetworkEvents & FD_READ) {
continue;
}
}
The key here is that WSAWaitForMultipleEvents() is very very lightweight. This example was for a connection thread for a server type socket, but implementing a similar theory in a client socket is simple.
Signature space for rent. Apply by email to....
|
|
|
|
|
Thanks.
The wait function (single) I use works well. I am just having a problem closing the handle of the event object.
Kuphryn
|
|
|
|
|
What is the message that a dialog receives when you bring another application on top of it?
|
|
|
|
|
There are most likely several; use Spy++ to find the ones you want. If the dialog was previously active, you'll most likely get WM_KILLFOCUS , WM_ACTIVATE , and possibly WM_ACTIVATEAPP .
Shog9
------
If you really what to get shitfacde tell a crowded bar that is is yourt borthday and hife your wallet. you ka will many more friends.
- David Wulff, Brithday selebrations, 9/19/02
|
|
|
|
|
Hello friends,
i would like to catch the WM_SET_TEXT message in an CEdit derived class.
My Function "OnSetText" is called (by Win/framework), but now is my problem: how can i set
the text of the control myself in my function?
When i use SetWindowText, i "call" my own function recursive..!
Thank you very much for your help!
Fiffi
|
|
|
|
|
um....set a flag when you start the recursion and if flag is set then don't recurse and clear the flag??? that's a guess
or on the OnSetText in your class, start a timer (perhaps using flag approach above) and then set the text on the timer call??
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Hello RedZenBird,
I don't would like to call the function recursive!
The command SetWindowText send the WM_SET_TEXT message to windowses to set her text. I would like to catch that message in my CEdit derived class/control (That part is done and OK).
But i would like to the the text in my WM_SET_TEXT-message-handler-function.
When i use SetWindowText my function calls recursive herself!
My question: How can i set the window text without SetWindowText/WM_SET_TEXT ?
(Sorry for my bad english!)
Fiffi
|
|
|
|
|
The point RedZenBird was trying to make is that you need to have a situation where OnSetText can do nothing if not appropriate:-
class CYourEditCtrl
{
protected:
BOOL bTextSet;
.....
}
void CYourEditCtrl::OnSetText( ... )
{
if (bTextSet) {
bTextSet = FALSE;
return;
}
bTextSet=TRUE;
SetText(....);
return;
}
Signature space for rent. Apply by email to....
|
|
|
|
|
Have you tried calling Default()?
Do you need to trap WM_SETTEXT, or would one of the EN_ messages do what you want?
Steve S
[This signature space available for rent]
|
|
|
|
|
You've subclassed an Edit control, and are receiving the WM_SETTEXT message. This message is sent to the control in order to change the text; it is the only (safe) way to accomplish this for an Edit control. So, you simply need to call the original window procedure.
If you are not modifying the text specified in the message, you can just call CEdit:OnSetText() or CWnd::Default() - both of these will call the origial Edit control procedure with the original message parameters.
If you *are* modifying the text, you will need to call CWnd::DefWindowProc() and pass in WM_SETTEXT for the message parameter, 0 for the second parameter (wparam), and a pointer to the string as the last parameter (lparam). Note that this method is not the same as ::DefWindowProc() , as it will call the original window procedure if the window was subclassed.
Have fun!
Shog9
------
If you really what to get shitfacde tell a crowded bar that is is yourt borthday and hife your wallet. you ka will many more friends.
- David Wulff, Brithday selebrations, 9/19/02
|
|
|
|
|
Hello friends,
Thank you very much for you help!
I begin with try/test...
Fiffi
|
|
|
|
|
I'm trying to change the value of a transfer var in a drop down list. The value that is selected is 10 off as my indexs start at 10 and go up instead of 0. So I have been trying to add 10 to this variable but it just won't take.
Help@!
|
|
|
|
|
First, you need to post some code. The following phrases in your description are a little hard to understand:
"indexs start and 10 and go up"
"it just won't take"
Item indices in a combo box control start at 0, and increase to the number of items in the list (minus 1). Period. If you need the selection index to be treated in some other way, you will have to apply that difference each time you retrieve the selection index from the combo box.
Since you are using a 'transfer var', I'll assume you are using MFC's DDX/DDV in a dialog box. Transfer variables are set from the dialog controls each time you call UpdateData(FALSE) . Every time you call UpdateData(FALSE) , your transfer variable is going to be set to the selection index of the combo box control, regardless of whatever was in the variable beforehand. So, if your transfer variable is m_xfer , and the 4th item in the combo box is selected, then:
m_xfer = 123456;
UpdateData(FALSE);
TRACE("m_xfer = %d\r\n",m_xfer); will display
m_xfer = 3 in the Output window.
Gary R. Wheeler
|
|
|
|
|
Is there a limit on the amount of timer's I can have running in an application, and how much overhead will there be in these timer events? I'm thinking about using up to 1000 timers in a window or even up to 2000 timers if two instances of the window are open.
I will set the timers to intervals of about 4 or 4.2 seconds and they will not all go off at the same time but that's about 250 (or 500) timer events per second in my worst case scenario.
Any thoughts? I could provide more details if needed.
|
|
|
|
|
Have you tried this? Something about having a thousand timers firing (even if it were possible) sounds a bit freakish to me....Can't you have a single timer fire and then use that timer event to 'fire other internal events' in your process?
For example, one app I've written uses an sorted array of "timed tasks" and then on every timer tick it increments the "array slot" for the tasks to be fired at that timer tick and fires each of them....I don't know if this concept works in your design....but I daresay you may wanna reconsider your timer strategy....
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Ok, here's the problem. I'm trying to make a simple radar type display, called a PPI. This one is different from most we've done previously, in that when you draw a target on the PPI, I do not want to see where the target's location was on the previous (radar) scan. Thus, I need to erase the target's location for the last scan before I draw the target's new location for the current scan. Also, keep in mind that some targets do not move but may disappear after several scans.
Now, in the past we just drew a target for say scan number n and then at scan number n+20, we would have a 20 target history onscreen since we did not erase the previous locations.
Now, I could probably do it with one timer but I was trying to make this simple. There are probably several approaches to doing this but tracking the targets, i.e. keeping track of their position from scan to scan and then correlating those targets from the current scan to the previous scan, is not simple. So, I thought if I made my target symbols intelligient with each one having its own timer, then it would erase itself (or make itself not visible) before being redrawn in the current scan being processed. The timer would go off just about the time when the next scan's data was being drawn in about the same location. Thus, the user would see targets from a previous scan for a select area disappear and then the updated (new) target being drawn within say .2 seconds.
As I said there are several ways of doing this, one approach would be to redraw all of the targets (XOR them so they erase) from the previous scan and then draw the new targets from the current scan but the problem with this is that radars take 4.6 seconds per scan (some are 10 and 12 second scans). Thus, I would have a blank display until the updated positions for these targets are drawn. Unacceptable.
If I want to make it smooth it requires some form of tracking. But, I want something simple. I hope this makes sense. The reason I thought the timers might work is because Direct3D or DirectDraw has something built into it that does something similar. e.g. U have a car or robot and you want it to move in some direction at some rate of speed.
|
|
|
|
|
Well, I think you are on the right track to have the targets be smart enough to erase/paint themselves.
Now, then, your question about having each object have a timer is still relevant. What I think we are trying to say to you is: instead of having each target have a timer that fires, consider:
1. Have a single timer ( 500 ms , 1 sec, whatever nyquist related rate you like )
2. Put all the target objects into some kind of prioritized collection.
3. Put a "timer_fired" method on each of the target objects.
4. When the single timer fires, have a smidge of logic that will determine where in the prioritized collection should be triggered by the timer event.
5. Inove the "timer_fired" method on each object stored at that location in the priority collecton.
Make sense?
Hope that helps.....
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Ok. I discussed this with another guy and we came up with a solution that only uses one timer. It's similar to what you are suggesting.
Basically, I will know the scan rate of the radar and create/set a timer that is 1/72th of the scan rate. This will allow me to categorize targets into 5 degree wedges. I will save what targets belong in what wedge and when the timer event fires, I will tell the targets in that wedge (container) to erase themselves.
Thanks for the suggestions. It's good to have somebody to talk to about stuff before you implement it.
|
|
|
|