CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 1999
    Location
    Idaho, Moscow
    Posts
    239

    CSoket, Receive stops

    Hi,

    I did following

    CSocket pSocket = new CSocket();
    pSocket->Create();
    pSocket->Connect("11.11.11.11","8000");

    ======================================
    len = pSocket->Send("asdfa", 6); ------------> Seems working

    len = 6

    len = pSocket->Receive(pBuf, 20); -----------> Stops


    What reason cause "Receive" stops?


    Thanks,

  2. #2
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147

    Re: CSoket, Receive stops

    CSocket is designed to operate in "blocking" mode, this means it will wait until the requested operation completes, or an error occurs.

    Specifically, in your example, it looks like the first call succeeds because there is at least 6 incoming bytes that are correctly received, then when you try to call Receive again, there are less than 20 more bytes waiting to be received.

    To use non-blocking style sockets, look at using the CAsyncSocket class.

    Be aware that the MFC implementation of these socket wrappers are not without their problems. They are fine to use for experimental, or learning purposes, but their use in commerical applications should be reviewed.

    ...the alternative to using these MFC socket wrapper classes is to use the Windows Sockets API calls, such as recv, etc.

    Here is a page describing the API routines.

    Hope this helps,

    - Nigel

  3. #3
    Join Date
    Sep 1999
    Location
    Idaho, Moscow
    Posts
    239

    Re: CSoket, Receive stops

    Hi Nigel

    Thank you very much. It helped me a lot. Could you give me an example about using "the Windows Sockets API calls" to conduct TCP/IP coomunication?

    Thank you very much

  4. #4
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147

    Re: CSoket, Receive stops

    You're very welcome

    Here is one of the best sites describing network programming that I've come across. There are a lot of articles describing how to use sockets, and there are also several examples there to get you started.

    Hope this helps,

    - Nigel

  5. #5
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: CSoket, Receive stops

    [ moved thread ]
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

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