Datagram Socket Crashes when too much data to send!

G

Guest

Hi,

I have already started a topic on a problem related to Datagram Socket Speed
Problem, it is at this address
http://msdn.microsoft.com/newsgroup...mobile-wince&lang=en&cr=US&sloc=en-us&m=1&p=1

I am still having problems with that one...

In my application, I am sending data "as fast as possible" into a datagram
socket, which is blocking, and which has a 400 kbyte sendbuffer. The code is
similar to this:

while (keepAlive)
{
byte[] data = dataSource.getData();

int sentData = socket.SendTo(data , 0, dataSize, SocketFlags.None,
remoteEndPoint);

//If I add this line, it is working fine
//Thread.Sleep(50);
}

If the Thread.Sleep() line is commented, the application will crash almost
instantly... I get no exception, no error... the connection with Visual
Studio .NET 2003 is lost, the application is shut down... and the Ipaq
network features are not working any more.. only a soft reset can bring it
back working.

I don't understand why the socket.SendTo() function does not block the
application untill the data is sent... It seems it only copies the data into
an internal buffer, and stupidly crashes when this buffer is full.

If I uncomment the line Thread.Sleep(), then the application is working.
This line is slowing down the application so that the data rate is low enough
for the socket to send it.

Paul G. Tobey tried to help me already. He suggested to check the value
returned by socket.SendTo()... unfortunately this value is always positive
and equals to the size of the byte[] the application is sending. So
everything seems to behave like normal, but it crashes completely....

What can I do to ensure the application is sending the data as fast as
possible ?
And also to be sure it will not crash ?

Thanks a lot for your patience to read this! :)

Lionel Reyero
 
G

Guest

Do you really require the buffer that big?

Have you tried use a smaller buffer (1 KB) max and send the data in chunks?
 
P

Paul G. Tobey [eMVP]

Remember that calls to SendTo() don't have their data concatenated into some
great big packet which is then sent to the destination (as they might on a
TCP socket, where there's no packetization defined; the data just looks like
a stream). Alex's suggestion is worth trying. Change *nothing* about the
send buffer size (leave it at the default, as this was undoubtedly the
best-tested configuration by MS). Make sure that none of your calls to
SendTo() are specifying more than 1000 or so bytes (there are packet size
restrictions on UDP). Still crashes? Device details?

Paul T.

Alex Yakhnin said:
Do you really require the buffer that big?

Have you tried use a smaller buffer (1 KB) max and send the data in
chunks?

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


Lionel Reyero said:
Hi,

I have already started a topic on a problem related to Datagram Socket
Speed
Problem, it is at this address :
http://msdn.microsoft.com/newsgroup...mobile-wince&lang=en&cr=US&sloc=en-us&m=1&p=1

I am still having problems with that one...

In my application, I am sending data "as fast as possible" into a
datagram
socket, which is blocking, and which has a 400 kbyte sendbuffer. The code
is
similar to this:

while (keepAlive)
{
byte[] data = dataSource.getData();

int sentData = socket.SendTo(data , 0, dataSize, SocketFlags.None,
remoteEndPoint);

//If I add this line, it is working fine
//Thread.Sleep(50);
}

If the Thread.Sleep() line is commented, the application will crash
almost
instantly... I get no exception, no error... the connection with Visual
Studio .NET 2003 is lost, the application is shut down... and the Ipaq
network features are not working any more.. only a soft reset can bring
it
back working.

I don't understand why the socket.SendTo() function does not block the
application untill the data is sent... It seems it only copies the data
into
an internal buffer, and stupidly crashes when this buffer is full.

If I uncomment the line Thread.Sleep(), then the application is working.
This line is slowing down the application so that the data rate is low
enough
for the socket to send it.

Paul G. Tobey tried to help me already. He suggested to check the value
returned by socket.SendTo()... unfortunately this value is always
positive
and equals to the size of the byte[] the application is sending. So
everything seems to behave like normal, but it crashes completely....

What can I do to ensure the application is sending the data as fast as
possible ?
And also to be sure it will not crash ?

Thanks a lot for your patience to read this! :)

Lionel Reyero
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top