locked
How can I request a value and wait for the value to be returned via MFC socket classes but not using http? RRS feed

  • Question

  • I have an arduin microcontroller connected to my home network and it is running a UDP server.

    I can successfully send data to it, using CAsynchSocket, and I can confirm it received by the microcontroller.

    But there seems to be no way I can use this class to receive data back from the microntroller immediately after the request.

    In fact the data arrives some time after my requesting function exits - which is useless.

    I can't use any blocking loops in my requesting function because that prevents virtual void OnReceive(int nErrorCode) from being called and the data from the microcontroller will never arrive while the loop is running.

    I am trying to use this to send small files between windows app and the micro controller - I can't use ftp with this micro controller

    Sunday, January 1, 2017 12:12 PM

All replies

  • On 1/1/2017 7:12 AM, Gregary Boyles wrote:

    I have an arduin microcontroller connected to my home network and it is running a UDP server.

    I can successfully send data to it, using CAsynchSocket, and I can confirm it received by the microcontroller.

    But there seems to be no way I can use this class to receive data back from the microntroller immediately after the request.

    Hence the "async" in CAsyncSocket. For "asynchronous", you know. If you want synchronous aka blocking communication, there's CSocket for that.

    In fact the data arrives some time after my requesting function exits - which is useless.

    Why so?

    I can't use any blocking loops in my requesting function because that prevents virtual void OnReceive(int nErrorCode) from being called and the data from the microcontroller will never arrive while the loop is running.

    So don't block. Return from the "requesting function", and then, when OnReceive is called, read the response and proceed with whatever you needed it for. That's how asynchronous communication works - you implement a state machine driven by network events.

    Sunday, January 1, 2017 2:01 PM
  • I have not used the MFC socket classes before so I need an example of using CSocket for datagrams.

    All I have found thus far is an example that uses CAsyncSocket, and what I have built following that example just does not work for me.

    Can you point me in the direction of an example of using the CSocket class - I need to know what correct sequence of functions to calls to make communication happen.

    The UDP server on the arduino is probably very rudimentary compared to MFC classes so I can most likely simulate another a CSocket object at the Arduino end.

    Sunday, January 1, 2017 2:11 PM
  • On 1/1/2017 9:11 AM, Gregary Boyles wrote:

    Can you point me in the direction of an example of using the CSocket class - I need to know what correct sequence of functions to calls to make communication happen.

    With CSocket, it's simple - you call Send() (or SendTo or similar) and then immediately call Receive (or ReceiveFrom et al). It'll block (in other words, won't return) until some data arrives from the network, or an error occurs.

    Sunday, January 1, 2017 2:21 PM
  • Hi Gregary Boyles,

    Thank you for posting here.

    If you want to use CSocket, please see the CSocket demo.

    the author will explain the easiest way to do socket programming using MFC socket classes.

    Best Regards,

    Hart

    if your issue has been resolved, please remember to close your thread by marking useful posts as answer that can be helpful for other person with same issue.


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 5, 2017 3:07 AM