tags:

views:

64

answers:

3

Is there a maximum on the number of sends on a socket? My sends work upto about 480 sends after which it starts returning -1

I'm using visual studio 2008 vc++ and socket programming using ACE.

+2  A: 

There's no specific limit, but obviously you can't keep pumping it out at the rate of knots if the receiving side isn't consuming it as fast. There are various buffers in between, and whatever software/hardware is maintaining each will put a limit on how much they'll accept. You need to wait until the receiving side consumes some data before you continue to send. You can get an asynchronous notification of when the socket becomes writeable again... check out select or poll for details if you're using the BSD API.

Tony
my receiver is going into blocking wait without data to read so thats not the problem
Rajesh
I wouldn't bet on it if I were you :-). You just need one buffer anywhere along the route to be momentarily flooded and the sending side will fail, irrespective of the state of the receiver. Really, you should try what I've suggested before you tell me I'm wrong.
Tony
ok..so how often should I do the check?..for every send?
Rajesh
Also depends on whether it's UDP/TCP/etc
sje397
@Rajesh: whenever the send doesn't return the number of bytes that you tried to send. I'm assuming you've got one send returning a lesser number, followed by lots of -1 errors. @sje397: very true... I'm assuming TCP. UDP packets will simply be lost if they arrive faster than the consumer reads them.
Tony
@Tony:yes.exactly.i'm using tcp
Rajesh
A: 

As far as i know there is no such limitation. I have sends that work on and on for days sending data without any problem.

Apparently there is some other problem. Please mention more details.

Also it could be that you are sending too much data and filling up the buffer. Check that also.

ckv
no...because my receiver is going into blocking without any data to read
Rajesh
+2  A: 

No, there's no upper limit on the number of send()s you can call.

Check out the man page for send (or whichever page is suitable for your platform) and try using the perror() (example: 'perror("error sending. system said");') call to see which error is being generated.

Note that -1 is a generic return code in this case and could mean anything from "My socket closed" to "The argument you're giving me is not a valid file descriptor"; thus, it's very hard to tell what's going on without some further information.

EDIT: The above answer assumed *NIX; this was a poor assumption.

Since you're using ACE, look at the ACE::send() documentation (doxygen is here). Additionally, there should be an ACE_OS::perror("error sending. system said") call (doxygen is here) that should work similar to what I've described above.

HTH

cubic1271
ok.I'll take a look at that.thanks
Rajesh