NetSamples.Common.Net
Class UdpListener

A UDP Listener

Field Summary
System.Net.IPAddress mcastaddress
NetSamples.Common.Net.UdpListener.ReceiveDelegate receiveDelegate
NetSamples.Common.Net.UdpListener.SendDelegate sendDelegate
System.Net.Sockets.Socket sock
bool stopping

Constructor Summary
UdpListener()
         Constructor.

Property Summary
System.Net.IPEndPoint LocalEndPoint
         Returns the local endpoint for the server.
System.Net.IPAddress MulticastAddress
         Returns the current multicast group address or sets a new one.

Method Summary
System.IAsyncResult BeginReceive(System.AsyncCallback callback, object state)
         Starts an asynchronous receive operation
void BeginReceive()
         Starts an asynchronous receive operation (private)
System.IAsyncResult BeginSend(NetSamples.Common.Net.Datagram datagram, System.AsyncCallback callback, object state)
         Starts an asynchronous send operation
void Bind(System.Net.IPEndPoint endpoint)
         Bind to the specified endpoint.
void BindReuse(System.Net.IPEndPoint endpoint)
         Bind to the specified endpoint.
void DropMulticastGroup(System.Net.IPAddress multicastgroup)
         Removes the listener from the specified multicast group.
NetSamples.Common.Net.Datagram EndReceive(System.IAsyncResult ar)
         Ends an asynchronous receive operation.
void EndSend(System.IAsyncResult ar)
         Ends an asynchronouse send operation
void Finalize()
         Finalizer
void JoinMulticastGroup(System.Net.IPAddress multicastgroup)
         Adds the listener to the specified multicast group.
void OnReceive(System.IAsyncResult ar)
         Internal receive handler: this handles the event from the MessageReader instance in the server and forwards it on to any objects attached to the MessageReceived event.
NetSamples.Common.Net.Datagram Receive()
         Attempts to receive a datagram. This call blocks until the receive completes.
void Send(NetSamples.Common.Net.Datagram datagram)
         Sends the specified message to the specified endpoint. For connected TCP sockets, the endpoint may be specified as null. Connected UDP sockets are not supported at this time.
void SetMulticastTtl(int ttl)
         Sets the Multicast Time to Live for the socket.
void Start()
         Starts the server. When started, the UDPListener issues a BeginReceive to start receiving packets. Whenever a packet is received, the Received event is fired.
void Stop()
         Stops the server.

Methods inherited from class System.Object
Equals, GetHashCode, GetType, MemberwiseClone, ToString

Event Summary
NetSamples.Common.Net.DatagramEventHandler Received
         The MessageReceived event is raised when a message is received by the server.


Field Detail

mcastaddress

protected System.Net.IPAddress mcastaddress


receiveDelegate

private NetSamples.Common.Net.UdpListener.ReceiveDelegate receiveDelegate


sendDelegate

private NetSamples.Common.Net.UdpListener.SendDelegate sendDelegate


sock

protected System.Net.Sockets.Socket sock


stopping

protected bool stopping

Constructor Detail

UdpListener

public UdpListener()

Constructor.

Property Detail

LocalEndPoint

public System.Net.IPEndPoint LocalEndPoint

Returns the local endpoint for the server.


MulticastAddress

public System.Net.IPAddress MulticastAddress

Returns the current multicast group address or sets a new one.

The UDPListener only supports membership of a singe multicast group at any point in time.

Method Detail

BeginReceive

public System.IAsyncResult BeginReceive(System.AsyncCallback callback,
                                        object state)

Starts an asynchronous receive operation


BeginReceive

protected void BeginReceive()

Starts an asynchronous receive operation (private)


BeginSend

public System.IAsyncResult BeginSend(NetSamples.Common.Net.Datagram datagram,
                                     System.AsyncCallback callback,
                                     object state)

Starts an asynchronous send operation


Bind

public void Bind(System.Net.IPEndPoint endpoint)

Bind to the specified endpoint.


BindReuse

public void BindReuse(System.Net.IPEndPoint endpoint)

Bind to the specified endpoint.


DropMulticastGroup

public void DropMulticastGroup(System.Net.IPAddress multicastgroup)

Removes the listener from the specified multicast group.


EndReceive

public NetSamples.Common.Net.Datagram EndReceive(System.IAsyncResult ar)

Ends an asynchronous receive operation.


EndSend

public void EndSend(System.IAsyncResult ar)

Ends an asynchronouse send operation


Finalize

protected void Finalize()

Finalizer


JoinMulticastGroup

public void JoinMulticastGroup(System.Net.IPAddress multicastgroup)

Adds the listener to the specified multicast group.


OnReceive

protected void OnReceive(System.IAsyncResult ar)

Internal receive handler: this handles the event from the MessageReader instance in the server and forwards it on to any objects attached to the MessageReceived event.


Receive

public NetSamples.Common.Net.Datagram Receive()

Attempts to receive a datagram. This call blocks until the receive completes.


Send

public void Send(NetSamples.Common.Net.Datagram datagram)

Sends the specified message to the specified endpoint. For connected TCP sockets, the endpoint may be specified as null. Connected UDP sockets are not supported at this time.


SetMulticastTtl

public void SetMulticastTtl(int ttl)

Sets the Multicast Time to Live for the socket.


Start

public void Start()

Starts the server. When started, the UDPListener issues a BeginReceive to start receiving packets. Whenever a packet is received, the Received event is fired.


Stop

public void Stop()

Stops the server.

Event Detail

Received

public NetSamples.Common.Net.DatagramEventHandler Received

The MessageReceived event is raised when a message is received by the server.