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. Sending data through winsock

Sending data through winsock

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestion
7 Posts 5 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.
  • A Offline
    A Offline
    Archer282
    wrote on last edited by
    #1

    while( true ) { cout<<"Send: "; cin>>szBuffer; send( client, szBuffer, sizeof(szBuffer), 0 ); if( strcmpi(szBuffer,"exit") == 0 ) break; } if szBuffer is something like "Hello world" then the server recieves the string in two parts the first being "Hello" and the second being "world" so i think you get my point, it seems to be breaking the data by spaces and sending each word it may be appending the space too, (havnt tested) now i want it to send "Hello world" all at once instead of by each word, i thought about replacing the spaces with something else, but i dont really want to do that anyone know what i can to do to solve this?

    S A G 3 Replies Last reply
    0
    • A Archer282

      while( true ) { cout<<"Send: "; cin>>szBuffer; send( client, szBuffer, sizeof(szBuffer), 0 ); if( strcmpi(szBuffer,"exit") == 0 ) break; } if szBuffer is something like "Hello world" then the server recieves the string in two parts the first being "Hello" and the second being "world" so i think you get my point, it seems to be breaking the data by spaces and sending each word it may be appending the space too, (havnt tested) now i want it to send "Hello world" all at once instead of by each word, i thought about replacing the spaces with something else, but i dont really want to do that anyone know what i can to do to solve this?

      S Offline
      S Offline
      Steve Mayfield
      wrote on last edited by
      #2

      Take a look at the WSARecvEx routine - it will tell you if the received message is a partial message. Steve

      1 Reply Last reply
      0
      • A Archer282

        while( true ) { cout<<"Send: "; cin>>szBuffer; send( client, szBuffer, sizeof(szBuffer), 0 ); if( strcmpi(szBuffer,"exit") == 0 ) break; } if szBuffer is something like "Hello world" then the server recieves the string in two parts the first being "Hello" and the second being "world" so i think you get my point, it seems to be breaking the data by spaces and sending each word it may be appending the space too, (havnt tested) now i want it to send "Hello world" all at once instead of by each word, i thought about replacing the spaces with something else, but i dont really want to do that anyone know what i can to do to solve this?

        A Offline
        A Offline
        Andrew Peace
        wrote on last edited by
        #3

        Look at the line

        send( client, szBuffer, sizeof(szBuffer), 0 );

        I presume szBuffer is comething like LPTSTR, LPSTR, TCHAR * or char *, in which case, the sizeof operator will return the size of the pointer, not the buffer. You need to pass in the size of the buffer, or use strlen (may be vulnerable to buffer overflows). -- Andrew.

        A 1 Reply Last reply
        0
        • A Archer282

          while( true ) { cout<<"Send: "; cin>>szBuffer; send( client, szBuffer, sizeof(szBuffer), 0 ); if( strcmpi(szBuffer,"exit") == 0 ) break; } if szBuffer is something like "Hello world" then the server recieves the string in two parts the first being "Hello" and the second being "world" so i think you get my point, it seems to be breaking the data by spaces and sending each word it may be appending the space too, (havnt tested) now i want it to send "Hello world" all at once instead of by each word, i thought about replacing the spaces with something else, but i dont really want to do that anyone know what i can to do to solve this?

          G Offline
          G Offline
          gamitech
          wrote on last edited by
          #4

          remember this: send(client,szBuffer,strlen(szBuffer),0); // so use strlen when sending recv(server,szBuffer,sizeof(szBuffer),0); // so use sizeof when receiving gabby

          1 Reply Last reply
          0
          • A Andrew Peace

            Look at the line

            send( client, szBuffer, sizeof(szBuffer), 0 );

            I presume szBuffer is comething like LPTSTR, LPSTR, TCHAR * or char *, in which case, the sizeof operator will return the size of the pointer, not the buffer. You need to pass in the size of the buffer, or use strlen (may be vulnerable to buffer overflows). -- Andrew.

            A Offline
            A Offline
            Archer282
            wrote on last edited by
            #5

            actually, szBuffer is defined as TCHAR szBuffer[512]; notice its not defined as a pointer, im not stupid, if it were defined as a pointer then sizeof(szBuffer) would return 4 but since its not a pointer it should return 512 how did you get that line to show up with a tan background? i have tried [code]somecode[/code] before it doesnt seem to work

            A C 2 Replies Last reply
            0
            • A Archer282

              actually, szBuffer is defined as TCHAR szBuffer[512]; notice its not defined as a pointer, im not stupid, if it were defined as a pointer then sizeof(szBuffer) would return 4 but since its not a pointer it should return 512 how did you get that line to show up with a tan background? i have tried [code]somecode[/code] before it doesnt seem to work

              A Offline
              A Offline
              Andrew Peace
              wrote on last edited by
              #6

              > im not stupid, Are you sure? TCHAR szBuffer[512] makes szBuffer a pointer, without a subscript it is synonymous to saying &szBuffer[0]... Being rude won't get you any help in these forums. Hope that was useful. -- Andrew.

              1 Reply Last reply
              0
              • A Archer282

                actually, szBuffer is defined as TCHAR szBuffer[512]; notice its not defined as a pointer, im not stupid, if it were defined as a pointer then sizeof(szBuffer) would return 4 but since its not a pointer it should return 512 how did you get that line to show up with a tan background? i have tried [code]somecode[/code] before it doesnt seem to work

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                »Archer282« wrote: how did you get that line to show up with a tan background? i have tried [code]somecode[/code] before it doesnt seem to work »Archer282« wrote: im not stupid How do you reconcile these two comments ? Code blocks are easy, if you have the ability to read ( hint: check the formatting links below if you can't work it out for yourself ). Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

                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