Click here to Skip to main content
15,902,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I have made a VC6 GUI which will act as a client.
I have been using "class CMySocket : public CAsyncSocket" for the socket programming where we have these following functions for TCP/IP communication

C#
virtual void OnAccept(int nErrorCode);
    virtual void OnClose(int nErrorCode);
    virtual void OnConnect(int nErrorCode);
    virtual void OnReceive(int nErrorCode);


Problem: While in continuous reception mode, the data from the server is received on the PC (verified by Wireshark) but does not enter my VC code given below:


C#
void CMySocket::OnReceive(int nErrorCode)
{
    // TODO: Add your specialized code here and/or call the base class

        if(nErrorCode==0)
    {
        ((CMyProject*)m_pWnd)->OnReceive();
    }

    CAsyncSocket::OnReceive(nErrorCode);
}



The communication between server & client happens flawlessly when the client is sending 32 bytes command & receiving some 20 bytes Acknowledgement but it does not work while receiving large chunk of data(1037 bytes)..

I had tried debugging by putting break-points in "SOCKCORE.CPP" and tried to debug the problem but while doing step debugging the program works fine and the overridden function "OnReceive" is called but when we run in continuous mode (no breakpoints). The reception halts after 1-2 chunks of 1037 bytes (though server has successfully sent the data & we receive it in our computer by wireshark).

Has anybody encountered the same problem? Pls help.
C++



Thanks.
Posted

1 solution

Doc says "This class is based on the assumption that you understand network communications. You are responsible for handling blocking, byte-order differences, and conversions between Unicode and multibyte character set (MBCS) strings. If you want a more convenient interface that manages these issues for you, see class CSocket."
So use CSocket, or better and portable Boost Asio[^]
 
Share this answer
 
Comments
iakashagrawal 4-Nov-11 2:07am    
To Doc,

Thanks. I will try using CSocket.

Actually, I did not understand that what could be the cause of the problem. One important point is that My project works absolutely fine in Win XP service Pack 2! though I have made similar Projects using AsyncSocket and they are working fine with Service Pack 3. Only this project is giving problem. I don't seem to have done anything different to the best of my knowledge. Also, the data is not continuously pumped by the server which in rare cases may result in discarding / loss of data due to buffer overflows. Server sends the 1KB chunk then waits for Acknowledgement(ACK) by the client before sending the next chunk. Care is taken by the client that the ACK is sent after all the processing of previous data so that the client is absolutely free to receive fresh data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900