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. Socket Program Problem!!!

Socket Program Problem!!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadminsecurityquestion
9 Posts 3 Posters 3 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.
  • J Offline
    J Offline
    John Bosko
    wrote on last edited by
    #1

    Hi, I am doing a very basic thing of sending data to a server and getting the reply back. For which first I have to send in a Login request and get authenticated, once authenticated, I have to send the actual data. The problem I am facing is when I send the data, it embeds some funny characters before the actual text, which is causing the problem. Upon further investigation, it was found that if I send the data without the login, it gets to the server correctly. Is there some kind of REFRESH!!! for the second time when the data is sent so that it has correct values? [CODE] ========================================= for login authentication: e = sendto(sd,"8888\n",89,0,(struct sockaddr *)&saServer,sizeof(saServer)); For sending Data: e = sendto(sd,"888808M5359846Test+Value\n"); ========================================== [CODE] The second sendto, does not send the data correctly. Is there some refresh after we do the first sendto? Kindly Help!!! Best Regards, John:((

    J R 2 Replies Last reply
    0
    • J John Bosko

      Hi, I am doing a very basic thing of sending data to a server and getting the reply back. For which first I have to send in a Login request and get authenticated, once authenticated, I have to send the actual data. The problem I am facing is when I send the data, it embeds some funny characters before the actual text, which is causing the problem. Upon further investigation, it was found that if I send the data without the login, it gets to the server correctly. Is there some kind of REFRESH!!! for the second time when the data is sent so that it has correct values? [CODE] ========================================= for login authentication: e = sendto(sd,"8888\n",89,0,(struct sockaddr *)&saServer,sizeof(saServer)); For sending Data: e = sendto(sd,"888808M5359846Test+Value\n"); ========================================== [CODE] The second sendto, does not send the data correctly. Is there some refresh after we do the first sendto? Kindly Help!!! Best Regards, John:((

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      From MSDN-doc I get that the 3rd parameter of ::sendto() is int len. Are you setting this one correctly to the length of the data you want to transmit? And: do you get an error-return in your variable e? -- "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski

      J 1 Reply Last reply
      0
      • J jhwurmbach

        From MSDN-doc I get that the 3rd parameter of ::sendto() is int len. Are you setting this one correctly to the length of the data you want to transmit? And: do you get an error-return in your variable e? -- "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski

        J Offline
        J Offline
        John Bosko
        wrote on last edited by
        #3

        Hi, yes the return variable is '0' which is correct. Thanks, John

        J R 2 Replies Last reply
        0
        • J John Bosko

          Hi, yes the return variable is '0' which is correct. Thanks, John

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          So, having 0 bytes transfered is correct? I don't think so! Something is rotten here, and I am of no help, 'cause I never used sockets. Sorry! But it seems you HAVE TO read the MSDN about this. "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski

          J 1 Reply Last reply
          0
          • J John Bosko

            Hi, I am doing a very basic thing of sending data to a server and getting the reply back. For which first I have to send in a Login request and get authenticated, once authenticated, I have to send the actual data. The problem I am facing is when I send the data, it embeds some funny characters before the actual text, which is causing the problem. Upon further investigation, it was found that if I send the data without the login, it gets to the server correctly. Is there some kind of REFRESH!!! for the second time when the data is sent so that it has correct values? [CODE] ========================================= for login authentication: e = sendto(sd,"8888\n",89,0,(struct sockaddr *)&saServer,sizeof(saServer)); For sending Data: e = sendto(sd,"888808M5359846Test+Value\n"); ========================================== [CODE] The second sendto, does not send the data correctly. Is there some refresh after we do the first sendto? Kindly Help!!! Best Regards, John:((

            R Offline
            R Offline
            Rage
            wrote on last edited by
            #5

            Maybe you should empty the socket buffer before restarting to use sendto again. How are you authenticating it (from the sender point of vue) ? Does the sender got something from the reciever (confirmation message ?) so that he is allowed to send data ? If yes, this could have been sent back if the buffer was not emptied. I experienced that a couple of months ago. ~RaGE();

            J 1 Reply Last reply
            0
            • R Rage

              Maybe you should empty the socket buffer before restarting to use sendto again. How are you authenticating it (from the sender point of vue) ? Does the sender got something from the reciever (confirmation message ?) so that he is allowed to send data ? If yes, this could have been sent back if the buffer was not emptied. I experienced that a couple of months ago. ~RaGE();

              J Offline
              J Offline
              John Bosko
              wrote on last edited by
              #6

              Hi, How do I empty the socket buffer? If you can help me out with it, I guess it would solve my problem!!! Kindly Help, John

              R 1 Reply Last reply
              0
              • J John Bosko

                Hi, yes the return variable is '0' which is correct. Thanks, John

                R Offline
                R Offline
                Rage
                wrote on last edited by
                #7

                John Bosko wrote: yes the return variable is '0' which is correct. which is _not_ correct. Try and give the length of the data you want to send as third parameter of the sendto. I think that this is really a buffer problem. When you send your data without preceding it by the login request, the buffer is empty (and not full with the loggin request stuff), so IMO that's why there is no problem in that case. ~RaGE();

                1 Reply Last reply
                0
                • J John Bosko

                  Hi, How do I empty the socket buffer? If you can help me out with it, I guess it would solve my problem!!! Kindly Help, John

                  R Offline
                  R Offline
                  Rage
                  wrote on last edited by
                  #8

                  John Bosko wrote: How do I empty the socket buffer? I was just looking for it, but i did not find anything, and i cannot remember myself :( Sorry .. I stiil think this should not happen if you receive the same amount of byte that you send, so be careful to the length parameter in sendto. Sorry i cannot help more. ~RaGE();

                  1 Reply Last reply
                  0
                  • J jhwurmbach

                    So, having 0 bytes transfered is correct? I don't think so! Something is rotten here, and I am of no help, 'cause I never used sockets. Sorry! But it seems you HAVE TO read the MSDN about this. "My opinions may have changed, but not the fact that I am right." Found in the sig of Herbert Kaminski

                    J Offline
                    J Offline
                    John Bosko
                    wrote on last edited by
                    #9

                    Oops!! sorry I gave you the return code '0' which means success. yes, there is a return confirmation which I am getting. But I am not selecting the entire return confirmation, just taking in first 40 bytes. Thanks, John

                    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