CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Posts
    82

    CSocket problem?

    I want to use socket to send and receive data with a website.
    I created my own CMySocket derived from CSocket, and overrided the OnSend and OnReceive methods:

    void CMySocket::OnReceive(int nErrorCode)
    {
    char strRecv[1024];
    Receive(strRecv, 1024);
    }

    void CClickSocket::OnSend(int nErrorCode)
    {
    Send("Get", 3);
    AsyncSelect(FD_READ);
    }

    then I used the this socket in one of document member function:

    m_pSocket = new CMySocket(this);
    m_pSocket->CAsyncSocket::Create()
    m_pSocket->Connect(szIP, 80)

    But when I ran program, only the OnSend function executed. The OnReceive function doesn't run at all (I've set a break to check it).

    Why??

  2. #2
    Join Date
    Jul 1999
    Location
    San Jose,CA
    Posts
    246

    maybe..

    This is what you should be using, if plan to use http

    HTTP

    Action Prerequisite
    Establish an HTTP connection.
    Create a CInternetSession as the basis of this Internet client application.
    Call CInternetSession::
    GetHttpConnection to create a CHttpConnection object.

    Open an HTTP file. Establish an HTTP connection.
    Call CHttpConnection::OpenRequest to create a CHttpFile object.
    Call CHttpFile::AddRequestHeaders.
    Call CHttpFile::SendRequest.
    Read an HTTP file. Open an HTTP file.
    Call CInternetFile::Read.
    Get information about an HTTP request. Establish an HTTP connection.
    Call CHttpConnection::OpenRequest to create a CHttpFile object.
    Call CHttpFile::QueryInfo.
    1. Search in MSDN
    2. Search in Google
    3. Search in CodeGuru.com
    4. Ask in the forum

    ABNM.....asih b*&6 nahi mardeh

  3. #3
    Join Date
    Feb 2004
    Posts
    82
    Thank you for your help. But I want to use socket to have a try. I wonder why this problem occurs.

  4. #4
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    [Moved thread]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured