Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. problem with ReceiveFrom() function

problem with ReceiveFrom() function

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadminquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sunny_vc
    wrote on last edited by
    #1

    Hi all, I am working on TFTP server application. When A client is requested for a file, My OnReceive() function is called. In the OnReceive(),I am unable to get the data requested. I used the function like CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); CAsyncSocket::OnReceive(nErrorCode); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); } Here I am able to get the IPAddress and Port correctly. But Unable to get data in the buff variable.But Size value is not zero. So what could be the problem? Please help me.

    Regards, Sunil Kumar

    V S M 3 Replies Last reply
    0
    • S sunny_vc

      Hi all, I am working on TFTP server application. When A client is requested for a file, My OnReceive() function is called. In the OnReceive(),I am unable to get the data requested. I used the function like CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); CAsyncSocket::OnReceive(nErrorCode); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); } Here I am able to get the IPAddress and Port correctly. But Unable to get data in the buff variable.But Size value is not zero. So what could be the problem? Please help me.

      Regards, Sunil Kumar

      V Offline
      V Offline
      Varghese Paul M
      wrote on last edited by
      #2

      Make sure that the value returned by the function "ReceiveFrom" is a positive number less than 100. Remember that the buffer ( buff[100]) you used to receive the data is sitting in the stack and will go out of scope when the function returns.

      S 1 Reply Last reply
      0
      • V Varghese Paul M

        Make sure that the value returned by the function "ReceiveFrom" is a positive number less than 100. Remember that the buffer ( buff[100]) you used to receive the data is sitting in the stack and will go out of scope when the function returns.

        S Offline
        S Offline
        sunny_vc
        wrote on last edited by
        #3

        Yeah I have checked the value itis returned. it is less than 100 only and Im checking the buffer just after the Receivefrom function.i.e it is not out of the scope.

        Regards, Sunil Kumar

        1 Reply Last reply
        0
        • S sunny_vc

          Hi all, I am working on TFTP server application. When A client is requested for a file, My OnReceive() function is called. In the OnReceive(),I am unable to get the data requested. I used the function like CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); CAsyncSocket::OnReceive(nErrorCode); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); } Here I am able to get the IPAddress and Port correctly. But Unable to get data in the buff variable.But Size value is not zero. So what could be the problem? Please help me.

          Regards, Sunil Kumar

          S Offline
          S Offline
          sudhir_Kumar
          wrote on last edited by
          #4

          CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); CAsyncSocket::OnReceive(nErrorCode); } Just try this way.

          -@SuDhIrKuMaR@-

          S 1 Reply Last reply
          0
          • S sudhir_Kumar

            CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); CAsyncSocket::OnReceive(nErrorCode); } Just try this way.

            -@SuDhIrKuMaR@-

            S Offline
            S Offline
            sunny_vc
            wrote on last edited by
            #5

            Thanks for the reply, but still there is no data in buff. I think atleast it must have the filename I am requesting from tftp client.!

            Regards, Sunil Kumar

            S 1 Reply Last reply
            0
            • S sunny_vc

              Thanks for the reply, but still there is no data in buff. I think atleast it must have the filename I am requesting from tftp client.!

              Regards, Sunil Kumar

              S Offline
              S Offline
              sudhir_Kumar
              wrote on last edited by
              #6

              Why you are using ReciveFrom not Revice?

              -@SuDhIrKuMaR@-

              S 1 Reply Last reply
              0
              • S sudhir_Kumar

                Why you are using ReciveFrom not Revice?

                -@SuDhIrKuMaR@-

                S Offline
                S Offline
                sunny_vc
                wrote on last edited by
                #7

                I need to know the host address and port. Even i tried receive() but no use.

                Regards, Sunil Kumar

                1 Reply Last reply
                0
                • S sunny_vc

                  Hi all, I am working on TFTP server application. When A client is requested for a file, My OnReceive() function is called. In the OnReceive(),I am unable to get the data requested. I used the function like CListenSocket::OnReceive(int nErrorCode) { char buff[100]; memset(buff,0,sizeof(buff)); CAsyncSocket::OnReceive(nErrorCode); if (nErrorCode) { Message.Format("OnReceive nErrorCode: %i", nErrorCode); AfxMessageBox(Message); return; } int Size = ReceiveFrom(buff, 100,IPAddress,Port); } Here I am able to get the IPAddress and Port correctly. But Unable to get data in the buff variable.But Size value is not zero. So what could be the problem? Please help me.

                  Regards, Sunil Kumar

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #8

                  First, there's no need to call CAsyncSocket::OnReceive(). It does nothing. If Size is > 0, then you received a datagram. If the data you expect isn't in the datagram, you need to look at the sender to see why. Mark

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups