john_bosko
December 11th, 2002, 05:07 AM
Hi,
How do I empty a socket buffer?
I am using sendto() function.
Many Thanks,
John
How do I empty a socket buffer?
I am using sendto() function.
Many Thanks,
John
|
Click to See Complete Forum and Search --> : Empty Socket Buffer john_bosko December 11th, 2002, 05:07 AM Hi, How do I empty a socket buffer? I am using sendto() function. Many Thanks, John j0nas December 11th, 2002, 03:32 PM I'm not sure I understand your question. Do you mean writing over the content of your send buffer? In that case, you can do: char buf[100]; /* ... */ memset(buf, 0, sizeof buf); /* clears the buffer */ /* ... */ Was that it? Mikey December 11th, 2002, 04:59 PM what do You mean with "empty" the buffer? Do You mean how to read You sent data? You can receive Your data with recvfrom. Mikey john_bosko December 11th, 2002, 11:42 PM Hi J0nas, My code is to do with client/server communication. There are 2 steps to be done, step 1 would be to get authenticated by the server once authenticated, I have to send the actual data. So when I do the first sendto() it goes through correctly. However, when I execute the second sendto() it goes with some junk data. In order to get the second sendto() to send correct data, I need to empty this buffer. ====================================== FOR THE AUTHENTICATION sendto(sd,"<REQ><LOGINID>8888</LOGINID>\n",30,0,(struct sockaddr *)&saServer,sizeof(saServer)); FOR THE ACTUAL DATA SENDING sendto(sd,"<REQ><MESSAGE>HELLO</MESSAGE>\n",32,0,(struct sockaddr *)&saServer,sizeof(saServer)); ========================================== It is at the second sendto() that I have a problem. On another note, if I send the second sendto() prior to the first sendto() then it works. So i presume it has got to do with emptying the buffer contents. Kindly help!!! John Originally posted by j0nas I'm not sure I understand your question. Do you mean writing over the content of your send buffer? In that case, you can do: [code] char buf[100]; /* ... */ memset(buf, 0, sizeof buf); /* clears the buffer */ /* ... */ Was that it? john_bosko December 11th, 2002, 11:44 PM Hi Mikey, My code is to do with client/server communication. There are 2 steps to be done, step 1 would be to get authenticated by the server once authenticated, I have to send the actual data. So when I do the first sendto() it goes through correctly. However, when I execute the second sendto() it goes with some junk data. In order to get the second sendto() to send correct data, I need to empty this buffer. [CODE] ====================================== FOR THE AUTHENTICATION sendto(sd,"<REQ><LOGINID>8888</LOGINID>\n",30,0,(struct sockaddr *)&saServer,sizeof(saServer)); FOR THE ACTUAL DATA SENDING sendto(sd,"<REQ><MESSAGE>HELLO</MESSAGE>\n",32,0,(struct sockaddr *)&saServer,sizeof(saServer)); ========================================== [CODE] It is at the second sendto() that I have a problem. On another note, if I send the second sendto() prior to the first sendto() then it works. So i presume it has got to do with emptying the buffer contents. Kindly help!!! John Originally posted by Mikey what do You mean with "empty" the buffer? Do You mean how to read You sent data? You can receive Your data with recvfrom. Mikey Mikey December 12th, 2002, 03:03 AM have You checked the socket-state with select()? It's important, to find out if You are allowed to write (and read)! Mikey john_bosko December 12th, 2002, 04:51 AM Originally posted by Mikey have You checked the socket-state with select()? It's important, to find out if You are allowed to write (and read)! Mikey Yes Mikey, everything is fine that end. John sgenie December 12th, 2002, 02:43 PM Are you sure the amount of data you stated in sendto was the right one? I mean, the string length seems to be different from these 30-32 values. john_bosko December 13th, 2002, 11:22 PM Originally posted by sgenie Are you sure the amount of data you stated in sendto was the right one? I mean, the string length seems to be different from these 30-32 values. Hi, Yes the string lengths are okay, the very fact that the first sendto() works perfectly eliminates this doubt. Secondly, If i send the second sendto() prior to the first one, it also goes thru correctly without any problem. It's 2 sendto()'s one after the other is a problem!!! Thanks, John DanM December 14th, 2002, 04:21 AM Most probably there is no problem with the sento calls and there is no need to empty any buffers. Are you sure the server receives the junk data from the same client ? Are you sure your server doesn't have some other bug that causes data corruption ? Is it only the data that looks strange or the lenght is also changed ? Can you please post some server code so we can get more details ? Thanks, Dan codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |