|
-
December 11th, 2002, 06:07 AM
#1
Empty Socket Buffer
Hi,
How do I empty a socket buffer?
I am using sendto() function.
Many Thanks,
John
-
December 11th, 2002, 04:32 PM
#2
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?
-
December 11th, 2002, 05:59 PM
#3
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
-
December 12th, 2002, 12:42 AM
#4
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.
[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));
==========================================
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?
-
December 12th, 2002, 12:44 AM
#5
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
-
December 12th, 2002, 04:03 AM
#6
have You checked the socket-state with select()? It's important, to find out if You are allowed to write (and read)!
Mikey
-
December 12th, 2002, 05:51 AM
#7
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
-
December 12th, 2002, 03:43 PM
#8
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.
-
December 14th, 2002, 12:22 AM
#9
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
-
December 14th, 2002, 05:21 AM
#10
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|