C# Class Snarf.Udp.UdpListener

A basic listener that listens for incoming UDP messages on the specified port and passes the event on to application code whenever a message is received.
Inheritance: IDisposable
Show file Open project: shellscape/Snarf Class Usage Examples

Protected Properties

Property Type Description
localMessagesOnly bool
port int
udp System.Net.Sockets.UdpClient

Public Methods

Method Description
Dispose ( ) : void
GetLocalSubnetMask ( IPAddress ipaddress ) : IPAddress
GetNetworkAddress ( IPAddress address, IPAddress subnetMask ) : IPAddress
IsInSameSubnet ( IPAddress localAddress, IPAddress otherAddress ) : bool
Start ( ) : void
Start ( AsyncCallback callback ) : void

Starts listening for messages on the specified port

Stop ( ) : void

Stops listening for messages and frees the port

UdpListener ( int port, bool localMessagesOnly ) : System

Creates a new UdpListener

Protected Methods

Method Description
Dispose ( bool disposing ) : void

Private Methods

Method Description
ProcessPacket ( IAsyncResult ar ) : void

When a message is received by the listener, the raw data is read from the packet and the PacketReceived event is fired.

Method Details

Dispose() public method

public Dispose ( ) : void
return void

Dispose() protected method

protected Dispose ( bool disposing ) : void
disposing bool
return void

GetLocalSubnetMask() public static method

public static GetLocalSubnetMask ( IPAddress ipaddress ) : IPAddress
ipaddress System.Net.IPAddress
return System.Net.IPAddress

GetNetworkAddress() public static method

public static GetNetworkAddress ( IPAddress address, IPAddress subnetMask ) : IPAddress
address System.Net.IPAddress
subnetMask System.Net.IPAddress
return System.Net.IPAddress

IsInSameSubnet() public static method

public static IsInSameSubnet ( IPAddress localAddress, IPAddress otherAddress ) : bool
localAddress System.Net.IPAddress
otherAddress System.Net.IPAddress
return bool

Start() public method

public Start ( ) : void
return void

Start() public method

Starts listening for messages on the specified port
public Start ( AsyncCallback callback ) : void
callback AsyncCallback
return void

Stop() public method

Stops listening for messages and frees the port
public Stop ( ) : void
return void

UdpListener() public method

Creates a new UdpListener
public UdpListener ( int port, bool localMessagesOnly ) : System
port int The port to listen for messages on
localMessagesOnly bool true to only listen for messages from the local machine;false to listen for messages from any source
return System

Property Details

localMessagesOnly protected property

Indicates if messages from remote machines should be allowed or not
protected bool localMessagesOnly
return bool

port protected property

The port to listen for messages on
protected int port
return int

udp protected property

The underlying UdpClient
protected UdpClient,System.Net.Sockets udp
return System.Net.Sockets.UdpClient