UDPClient.Send Checking

G

Guest

Hi ,

I need help on this one.. any help would be appreciated, heres my code:

My code for sending using UDPClient:

public void Send( string Message)
{
if ( !isRunning ) return ;
try
{
byte[] bs = System.Text.Encoding.UTF8.GetBytes(Message);
thisClient.Send(bs,(int) bs.Length, RemoteEndPoint);
}
catch(Exception e)
{
if(OnError!=null)
OnError("Error Sending: " + e.Message);
done = true;
isRunning = false;
}
Thread.Sleep(100);
}

My code for Listen():

private void Listen()
{
done = false;
while(!done)
{
try
{
IPEndPoint IPEndPointNull = new IPEndPoint( IPAddress.Any,
this.mygroupPort );
byte[] bs = thisClient.Receive( ref
IPEndPointNull);
string msg = System.Text.Encoding.UTF8.GetString(bs,0,bs.Length);
if ( OnRecieve != null )
OnRecieve(msg);
}
catch(Exception e)
{
if(OnError!=null)
OnError("Error Recieving: " + e.Message);
done = true;
isRunning = false;

}
}
}


Problem:

How can i check if the one i sent is correctly received by the listener and
how i pass back to the send() telling it that the message sent was not right
needs to retry sending? and how i do check if the listener did not receive
the message sent? any idea? i really would appreciate any help..thanks
 
F

Franz

Hi Rain,
How can i check if the one i sent is correctly received by the listener
...

afaik there exists the OSI model that ensures correct transport through
several layers

http://en.wikipedia.org/wiki/OSI_model

that means the layer below the UDP, the IP, is already checking for
correctness.

If you don't want to trust that, you can use the TCP protocol (TCPClient)
this is a connection-oriented protocol that ensures the receiving of the
message (and it should be correct).

Also you can add same additional data to your message, such as a checksum or
other, e.g. XOR every char (of your message) and append the result to the
message, so you can check this on the other side. (by the way, the lower
levels also check with checksums, so it would be twice or more often)

... and
how i pass back to the send() telling it that the message sent was not
right
needs to retry sending? ...

Use TCP, or build your own protocol basing on UDP. (choose a word that marks
the kind of message: e.g. RTY or ACK)
... and how i do check if the listener did not receive
the message sent?

with UDP it's not possible to check this, it sends the message into the
cable and forgets everything about it.
And how should the destiny realize that there should be something to
receive? - So use TCP


I hope all is right and can help you. (my first post in Newsgroups)

Greets
Franz
 
H

Hadi Hariri

that means the layer below the UDP, the IP, is already checking for
correctness.

Actually that's not entirely correct. UDP is a protocol that does not
perform checking and it does not assure that packets arrive in
sequence. You need to either use a sort of acknowledgement process by
sending ACK's back and forth to make sure the packets arrive or if you
do not really need to use UDP, then use TCP. THat does guarantee
delivery and in order.
 

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