|
What state is the connection in (according to netstat)? CLOSE_WAIT?
When the connection drops, recv() will either return 0 or SOCKET_ERROR (WSAGetLastError() will get
the error code) - I can't remember which right off hand (brain in screen-saver mode). Either
way, when you get an error on send() or recv() you can notify the 3rd application that the
connection dropped. A breakpoint right after a recv() call will show you which occurs when you
switch off the connection.
Lost connections will linger (you'll see them in netstat) until you officially close the socket or the
application. Therefore, when you detect the network down you should close the socket when unrecoverable
error codes are returned (they are listed in the send()/recv() API specs).
Hope this helps a little
Mark
|
|
|
|
|
Thanks for the tip, as I mentioned before when I disconnect the wireless network of the computer so that the connection ids dropped, netstat still shows that the connection is stablished!? until I close one of the application. and as my application should receive messages from the other application through the socket, I do not understand that the connection is down. Only when IN close the second application, I get the socket closed message and in netstat I can see close_wait.
Thanks,
|
|
|
|
|
Yes, you'll see the connection in netstat because the socket is still allocated even though it
may be disconnected physically. It will remain in CLOSE_WAIT (waiting for close as the name
implies) until you call closesocket(). Even after calling closesocket(), if there is/was pending
data on the connection it will "linger" by default for I think 120 seconds (so you'll see it in
netstat for that long). To force it to close immediately you can turn off the linger option for
the socket, something like:
linger Linger;
Linger.l_onoff = 1;
Linger.l_linger = 0;
::setsockopt(hSocket, SOL_SOCKET, SO_LINGER, (const char *)&Linger, sizeof(linger));
::closesocket(hSocket);
hSocket = INVALID_SOCKET;
|
|
|
|
|
Send a ping packet to the other IP address. If it doesnt come back, youknow the link is dead.
Truth is the subjection of reality to an individuals perception
|
|
|
|
|
You could wait until the TCP/IP stack reports that the connection is down (can take very long). Alternatively send a small connection testing packet (e.g. smilar to IRC's PING/PONG mechnism), sometimes you will receive immediately an error saying that the connection is down... or you can timeout the connection if you haven't received a connection test packets from the other peer for a while.
[corrected typos]
|
|
|
|
|
Why does the mousewheel event not scroll the window in a CRichEditView?
Mark
|
|
|
|
|
CRichEditView class doesn't handle the WM_MOUSEWHEEL event.
You can derive a class from CRichEditView and handle it yourself.
Mark
|
|
|
|
|
It works on Win98 machines. Trying it on XP machines I find that the mouse wheel button doesn't scroll the view window. Anyway, I fixed it by handling the OnMouseWheel() event.
BOOL CMyEditView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
CRichEditCtrl & rc = GetRichEditCtrl();
if( zDelta < 0 )
rc.LineScroll(3, 0);
else
rc.LineScroll(-3, 0);
return CRichEditView::OnMouseWheel(nFlags, zDelta, pt);
}
-- modified at 21:19 Monday 23rd October, 2006
Mark
|
|
|
|
|
Mark F. wrote: It works on Win98 machines. Trying it on XP machines I find that the mouse wheel button doesn't scroll the view window.
Oh ok - At first I thought maybe different common controls library. Checked and it's feature
from Rich Edit 1.0 on.
All I can think of off hand is the control doesn't have focus. Does it still not scroll if you
click in the control somewhere then turn the wheel?
Mark
|
|
|
|
|
Which is the best to use? char*, vector or std::string
I'm searching for the best way to manipulate strings. I've historically used char* with strstr, strtok, etc. I've also used CStrings, but trying to get away from them.
I'm hoping to join the present and use containers whenever possible. I'm wondering if I can use a vector instead or is it best to use std::string.
I have to do all the standard string stuff, copying, searching, parsing, etc.
Ideas?
-C
|
|
|
|
|
That all depends on what you are doing. Use char* as little as possible. string is nice when you don't have to worry about multithreaded issues. If you are passing strings between threads, use vector<char> since it isn't reference counted.
For more descriptive details, check out Effective C++ and Effective STL by Scott Meyers.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: since it isn't reference counted.
So how does that solve all the synchronization issues? Depending on the use-model you could create just as many problems using a vector.
led mike
|
|
|
|
|
led mike wrote: So how does that solve all the synchronization issues?
Reference counting is not multithreading-friendly by default Having said that, not all versions aof std::string are reference counted - for instance the Dinkumware one that ships with VC++ is not. Of course, relying on a particular internal implementation is generally a bad idea.
|
|
|
|
|
Nemanja Trifunovic wrote: for instance the Dinkumware one that ships with VC++ is not.
Last time I checked, it was. Link
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
led mike wrote: So how does that solve all the synchronization issues?
It doesn't solve all synchronization issues. STL isn't threadsafe, so you have to use protection around any access to it anyway, but there are issues with passing strings around. I can't remember all the details (and I don't have my copy of Effective STL with me at the moment to look it up) off the top of my head.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: It doesn't solve all synchronization issues.
Ok, sorry my post was probably just stupid.
Zac Howland wrote: I can't remember all the details
This is not simply an oversight; current reference counted implementations may fail for
more complicated examples. They may fail even for s[1] == s[2] if the string s is simultaneously
examined (merely examined, not necessarily modified) by another thread.
SGI Reference[^]
led mike
|
|
|
|
|
|
If you are doing MFC (or want to include the specific headre) then use CString. Otherwise use the string template.
Truth is the subjection of reality to an individuals perception
|
|
|
|
|
How can i access CDialog class from antoher class
that declare in CDialog base application?
best regards,
M.J.M.
|
|
|
|
|
mostafa_pasha wrote: How can i access CDialog class...
Do you mean a CDialog -derived class?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
for example i have CMyFile that is generic class
(my project is CDialog base such as CMyDialog) how
can i access CMyDialog through CMyFile?
is that anyway that call CMyDialog's function from CMyFile
class?
Best regards.
M.J.M.
|
|
|
|
|
CMyFile::Method()
{
CMyDialog dlg;
dlg.DoModal();
}
?
--
Not a substitute for human interaction
|
|
|
|
|
mostafa_pasha wrote: is that anyway that call CMyDialog's function from CMyFile
class?
Sure, but why would you want to? By allowing CMyFile access to the internals of CMyDialog , you have thus tied the two together (i.e., encapsulation). It's especially troublesome if you are wanting CMyFile to manipulate a UI component (e.g., progress bar) that CMyDialog owns. You should be posting a message to CMyDialog instead.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
did you try it?
CMainClass *m_Main=(CMainClass*)GetParent();
m_Main->your variables
|
|
|
|
|
Hi,
it does not work.
GetParent get one argument as HWND.
i change it ,
<br />
CMainClass *m_Main=(CMainClass*)GetParent(theApp.GetMainWnd()->m_hWnd);<br />
but in dialog base application , compiler say " error C2065: 'theApp' : undeclared identifier"
now how can i get pointer to CVerApp class?
CVerApp * = ???;
which function exist to point to my CVerApp?
Best Regards.
M.J.M.
|
|
|
|