socket programming
-
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
-
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
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
-
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
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] -
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]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
-
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
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
-
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
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]