Can anyone help me! I have been developing a Client-Server networking application. In the server application, I have defined a class CMyCAsyncSocket as follows:
class CMyCAsyncSocket : public CAsyncSocket
{
:
private: //mine
CDialog* m_pWnd;
public: //mine
void SetParent(CDialog *pWnd) { m_pWnd = pWnd; }
protected://mine
virtual void OnAccept(int iErrorCode) {
if (iErrorCode == 0){//Successful Accept()
((CMyCAsyncSocket*)m_pWnd)->OnAccept(iErrorCode);
} else
exit(-1);
}
virtual void OnConnect(int iErrorCode) {
if (iErrorCode == 0){
((CMyCAsyncSocket*)m_pWnd)->OnConnect(iErrorCode);
} else
exit(-1);
}
virtual void OnSend(int iErrorCode) {//Successful Send()
if (iErrorCode == 0){
((CMyCAsyncSocket*)m_pWnd)->OnSend(iErrorCode);
} else
exit(-1);
}
virtual void OnReceive(int iErrorCode) {
if (iErrorCode == 0){
((CMyCAsyncSocket*)m_pWnd)->OnReceive(iErrorCode);
} else
exit(-1);
}
virtual void OnClose(int iErrorCode) {
if (iErrorCode == 0){
((CMyCAsyncSocket*)m_pWnd)->OnClose(iErrorCode);
}//if
((CMyCAsyncSocket*)m_pWnd)->Close();
exit(-1); //end this application
}
};
In the server/client application, I inserted the following statements:
CMyCAsyncSocket m_sMySocket; //for my network connection
:
M_sMySocket.SetParent(this); //as the book of mine instructs me to do!(don’t know why though!”)
I have these event functions defined in the CMAsyncSocket class to ensure that, if the network connection ends on the other side (i.e. the client side) for the reason that the client application has crashed without calling Close( ), the event functions of the server notice it and exit( ) call in them will end the server application too. Unfortunately or strangely, when I ran the both of the client and server applications and test it, it just did not happen! What have I done wrong?
I know the theory of TCP/IP protocol. My understanding is that , if a network connection on one side ends (whether the application of that side ends its side of the network properly calling Close( ) or it has just crashed terminating itself), the other side will notice it in a while and will close its side of the network connection too and any attempt to use the network connection by Send, Receive, and etc in the application after the close of the network connection will cause errors. If this is correct, I just can not understand why my testing has proved me wrong! Can anybody enlighten me on this issue.
Looking forward to hearing from you guys!
Thanks
Chong.
Enter your message below
Sign in or Join us (it's free).