Stuck with UdpState

Can anyone help me with a problem I'm having trying to get UdpClient.BeginReceive working? I've been trying the example given on MSDN, which gives this section of code to use:

public static void ReceiveCallback(IAsyncResult ar)

{
UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u;
IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e;

Byte[] receiveBytes = u.EndReceive(ar, ref e); string receiveString = Encoding.ASCII.GetString(receiveBytes); Console.WriteLine("Received: {0}", receiveString);
messageReceived = true;
}

The part I am having problems understanding is the first two lines... UdpClient and IPEndPoint, more specifically the UdpState part of them. I can't find UdpState anywhere, so I came to the conclusion that I must make that myself (a class?), but I have no idea as to what to put in it. I've had a look on Google but couldn't find anything useful.

Any help would be appreciated.

[992 byte] By [AntiSilence] at [2007-12-24]
# 1
Forget about the Udpstate. If you want to give BeginReceive and EndReceive a try go to this link http://www.csharp-home.com/index/tiki-read_article.php?articleId=85.
Saania at 2007-10-8 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2

A simple class like this will do

class UdpState
{
public UdpClient u;
public IPEndPoint e;
}

soblo at 2007-10-8 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 3

Look explanation from example in the following link: UpdState . It's state object what you are casting to client object. As Saania say, you don't need intermediate object at all!

Peca55 at 2007-10-8 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 4
This answer is flagged as correct but it's TCP-based while the question is UDP-based. No comprendo.
jebbushell at 2007-10-8 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified