Datagram Socket Speed Problem

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

I am doing a streaming application from Ipaq to Ipaq. I'm transmiting the
data over a Datagram Socket. One thread is dedicated to sending the data. It
is something alike this :

socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);

//set a large send buffer to the socket (400 ko)
socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveBuffer, 400000);

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

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

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

The dataSize is 38000 bytes. The while loop is executed about 30 times a
second, so it represents a bitrate of around 10 Mbit/S ! which is much more
than my wireless lan network capacity.

The program behavior is the following :
The receiver program start receiving packets... and after about 10 packets,
it is receiving nothing.
The sender program (described above) reports it is sending packets without
interruption even though the receiver is receiving nothing.... after 1 minute
or so, the sender crash "assembly not found exeception", and a soft restart
of the Ipaq is the only way to get it working smooth again.

If I uncomment the line :
Thread.Sleep(50);
the sender works without crashing, and the receiver keeps receiving all the
packets.

It seems that the Socket is not working properly when it is asked to
transmit more data than what it is physically possible to transmit.
I expected the socket.SendTo method to block until the data are actually
sent, so that it would block long enough to slow down the program to the
speed matching the maximum bitrate that can be supported by the network...
but it seems it is not the case. (by the way, I checked the socket has
blocking = true).

I can't let the Sleep operation.. because the data I am sending are real
time, and should be sent as fast as possible..

My questions are :

what's wrong with the socket ?
why doesn't it block longer, to send the data at an appropriate rate?
what can I do to my program to be sure it will not crash, and to send the
data as fast as possible.

Thanks a lot!

Lionel Reyero
.



Relevant Pages

  • Re: closing ASyncSocket
    ... I reread the help for the ShutDown() call. ... not close the socket, and resources attached to the socket will not be freed ... What if I want to Closethe connection to return resources. ... receiving side after I received the last data. ...
    (microsoft.public.vc.mfc)
  • Re: BeginReceive return zero length buffer when run ,and work correctly when use step by step debug
    ... Your first read is receiving 0 bytes? ... Your async socket listens and receives 500 bytes (your total buffer size ... But the data remains on the socket, until such time as it IS ... With a stream-oriented socket (eg TCP), ...
    (microsoft.public.dotnet.languages.csharp)
  • Exception trying to read/write from C# server socket on iPaq
    ... to connect to the server from the same iPaq. ... to read or write to the socket I get an exception: ... "An existing connection was forcibly closed by the remote host" ... // Do something with the client request here. ...
    (microsoft.public.pocketpc.developer.networking)
  • Re: Handling multiple connections
    ... each time select says the socket has more data. ... All data being sent by clients are prepended with a header that indicates ... received and thus delays receiving on the other readable sockets. ... When the client closes the connection, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Socket Communication with Laptop
    ... then keep receiving until that many bytes have arrived and then stop. ... The laptop seems to be sending at 1024 for a 1mb file. ... to determine if there is more data in the socket buffer to receive. ... SOCKET sockDest; ...
    (microsoft.public.windowsce.embedded.vc)