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 programming

socket programming

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studiohelp
6 Posts 3 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.
  • L Offline
    L Offline
    laggraw
    wrote on last edited by
    #1

    Hello friends, 1.I am facing one small problem in socket programming, my client is in c (visual studio)and client is in VB.when i am sending data from client it is sending 81 byte string (correct data)on reciever end some unwanted data(ìÿ¼³W|l) it is also appending in the correct data. 2.One more problem is that because client is sending at the fast rate data is accumulated on reciever end if the buffer size is greater(e.g.260) then correct data size(81) and after 3-4 string of correct data that unwanted data (ìÿ¼³W|l)is appending at the end. If anyone have any solution to this problem plz suggest me the solution Lalit Aggarwal

    P C 2 Replies Last reply
    0
    • L laggraw

      Hello friends, 1.I am facing one small problem in socket programming, my client is in c (visual studio)and client is in VB.when i am sending data from client it is sending 81 byte string (correct data)on reciever end some unwanted data(ìÿ¼³W|l) it is also appending in the correct data. 2.One more problem is that because client is sending at the fast rate data is accumulated on reciever end if the buffer size is greater(e.g.260) then correct data size(81) and after 3-4 string of correct data that unwanted data (ìÿ¼³W|l)is appending at the end. If anyone have any solution to this problem plz suggest me the solution Lalit Aggarwal

      P Offline
      P Offline
      Parthi_Appu
      wrote on last edited by
      #2

      laggraw wrote:

      on reciever end some unwanted data(ìÿ¼³W|l) it is also appending in the correct data

      Set the receiving buffer to zero or append a null('\0') charecter at the end the receiving data. the end can be found out by the return value of the recv function. Hope it will help you..


      Do your Duty and Don't expect the Result

      L 1 Reply Last reply
      0
      • L laggraw

        Hello friends, 1.I am facing one small problem in socket programming, my client is in c (visual studio)and client is in VB.when i am sending data from client it is sending 81 byte string (correct data)on reciever end some unwanted data(ìÿ¼³W|l) it is also appending in the correct data. 2.One more problem is that because client is sending at the fast rate data is accumulated on reciever end if the buffer size is greater(e.g.260) then correct data size(81) and after 3-4 string of correct data that unwanted data (ìÿ¼³W|l)is appending at the end. If anyone have any solution to this problem plz suggest me the solution Lalit Aggarwal

        C Offline
        C Offline
        Cedric Moonen
        wrote on last edited by
        #3

        What are you sending exactly ? Are the packets always constant size ? If no, how are you reading the data (show the code when you call recv funtion). The socket will never append data: it just send what you asked it to send. So either: - you send too much data - or you try to read data after the data you received (so you read in memory after the received data, which is uninitialize memory, which explains those garbage characters).


        Cédric Moonen Software developer
        Charting control [v1.2]

        L 1 Reply Last reply
        0
        • C Cedric Moonen

          What are you sending exactly ? Are the packets always constant size ? If no, how are you reading the data (show the code when you call recv funtion). The socket will never append data: it just send what you asked it to send. So either: - you send too much data - or you try to read data after the data you received (so you read in memory after the received data, which is uninitialize memory, which explains those garbage characters).


          Cédric Moonen Software developer
          Charting control [v1.2]

          L Offline
          L Offline
          laggraw
          wrote on last edited by
          #4

          Actually my client in VB, there we declared a string variable and we are appending data into that and after that we are sending data to the server which is in simple C language, where we declare a 512 byte buffer to collect the data.Data is of variable size vary between 76 to 83 byte. Actually code is already written we just modifying it, perviously we are using this program on same host, but now our customer want to use this program on different host, so actually becoz buffer was very large so data is accumulating in the buffer before reading so we got some accumulated data and some corrupt data also. Now what we did we just filling rest of the space of buffer by'*'(on client side) and taking the correct data on server side upto 1st '*' is encounter. But in this approach we are facing one more problem we faced that some times data is correct some time some bytes of data is coming between '*' like correct data: 115237887261448874974239***************************************************** uncorrect data: ********************************78798**************************************** i am not able to understand why these byte coming in between '*'. Sorry sir our code is simple on like any other simple program, but i cant share u may code. thanks Lalit Aggarwal

          C 1 Reply Last reply
          0
          • P Parthi_Appu

            laggraw wrote:

            on reciever end some unwanted data(ìÿ¼³W|l) it is also appending in the correct data

            Set the receiving buffer to zero or append a null('\0') charecter at the end the receiving data. the end can be found out by the return value of the recv function. Hope it will help you..


            Do your Duty and Don't expect the Result

            L Offline
            L Offline
            laggraw
            wrote on last edited by
            #5

            Actually problem is not so simple, our client is in VB where we declare on string type variable and we are appending the structure in the vairbel e.g. 10 times then send the data.This dat may vary between 76 to 83 bytes. On client side we delared the a buffer of 512 byte, which is already declared in the orginal code,the data which are coming from client side is accumulating in the buffer before we read it from it. So what we did for this problem we just filled rest of the space of buffer with some extra character and on receiver side we are taking correct data upto that extra character.But one new problem we are facing in this approach that sometimes data is coming between extra character like correct data format 8172646124975975570950098908********************************************** unwanted/corrupted data ************************45667********************************************* so i am not able to understand why this data coming in between the extra character. Thanx Lalit Aggarwal

            1 Reply Last reply
            0
            • L laggraw

              Actually my client in VB, there we declared a string variable and we are appending data into that and after that we are sending data to the server which is in simple C language, where we declare a 512 byte buffer to collect the data.Data is of variable size vary between 76 to 83 byte. Actually code is already written we just modifying it, perviously we are using this program on same host, but now our customer want to use this program on different host, so actually becoz buffer was very large so data is accumulating in the buffer before reading so we got some accumulated data and some corrupt data also. Now what we did we just filling rest of the space of buffer by'*'(on client side) and taking the correct data on server side upto 1st '*' is encounter. But in this approach we are facing one more problem we faced that some times data is correct some time some bytes of data is coming between '*' like correct data: 115237887261448874974239***************************************************** uncorrect data: ********************************78798**************************************** i am not able to understand why these byte coming in between '*'. Sorry sir our code is simple on like any other simple program, but i cant share u may code. thanks Lalit Aggarwal

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              Why don't you simply prepend the size of the data at the begining of the packet and only send what you need to send (without all those unnecessary * characters) ? On the receiver side, read first the size of the data and then read the appropriate number of bytes.


              Cédric Moonen Software developer
              Charting control [v1.2]

              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