C# Class Protogame.MxDispatcher

The Mx dispatcher; this handles receiving messages on the UDP client and dispatching them to the correct connected Mx client.
Datei anzeigen Open project: RedpointGames/Protogame Class Usage Examples

Public Methods

Method Description
Close ( ) : void

Closes the dispatcher permanently, terminating all inbound and outbound connections.

Connect ( IPEndPoint endpoint ) : MxClient

Explicitly connect to the specified endpoint, assuming there is an Mx dispatcher at the specified address.

This method is used to explicitly add clients, not to start the dispatcher. The dispatcher does not require an explicit start.

Disconnect ( MxClient client ) : void

Disconnects the specified Mx client. This removes it from the group that owns it, and prevents it from reconnecting to this dispatcher implicitly.

Disconnect ( MxClientGroup clientGroup ) : void

Disconnects the entire Mx client group, disconnecting all clients inside it.

GetBytesLastReceivedAndReset ( ) : int
GetBytesLastSentAndReset ( ) : int
MxDispatcher ( UdpClient client ) : System

Initializes a new instance of the MxDispatcher class.

MxDispatcher ( int port ) : System

Initializes a new instance of the MxDispatcher class.

PlaceInGroup ( MxClient client, string identifier ) : MxClientGroup

Places the specified Mx client in the specified group.

Send ( MxClient client, byte packet, bool reliable = false ) : void

Queue a packet for sending to the specified client.

Send ( MxClientGroup group, byte packet, bool reliable = false ) : void

Queue a packet for sending to the specified endpoint.

Update ( ) : void

Updates the dispatcher, receiving messages and connecting clients as appropriate.

this ( string identifier ) : MxClientGroup

Retrieves the client group for the given identifier.

Protected Methods

Method Description
OnClientConnected ( MxClient client ) : void

Raise the ClientConnected event.

OnClientDisconnectWarning ( Protogame.MxDisconnectEventArgs e ) : void

Raise the ClientDisconnectWarning event.

OnClientDisconnected ( MxClient client ) : void

Raise the ClientDisconnected event.

OnMessageAcknowledged ( Protogame.MxMessageEventArgs e ) : void

Raise the MessageAcknowledged event.

OnMessageLost ( Protogame.MxMessageEventArgs e ) : void

Raise the MessageLost event.

OnMessageReceived ( Protogame.MxMessageEventArgs e ) : void

Raise the MessageReceived event.

OnMessageSent ( Protogame.MxMessageEventArgs e ) : void

Raise the MessageSent event.

OnReliableReceivedProgress ( Protogame.MxReliabilityTransmitEventArgs e ) : void

Raise the ReliableReceivedProgress event.

OnReliableSendProgress ( Protogame.MxReliabilityTransmitEventArgs e ) : void

Raise the ReliableSendProgress event.

Private Methods

Method Description
AssertNotClosed ( ) : void

Assert that the dispatcher has not been closed.

OnClientDisconnectWarning ( object sender, Protogame.MxDisconnectEventArgs e ) : void

Handle receiving a DisconnectWarning event from a client.

OnClientMessageAcknowledged ( object sender, Protogame.MxMessageEventArgs e ) : void

Handle receiving a MessageAcknowledged event from a client.

OnClientMessageLost ( object sender, Protogame.MxMessageEventArgs e ) : void

Handle receiving a MessageLost event from a client.

OnClientMessageReceived ( object sender, Protogame.MxMessageEventArgs e ) : void

Handle receiving a MessageReceived event from a client.

OnClientMessageSent ( object sender, Protogame.MxMessageEventArgs e ) : void

Handle receiving a MessageSent event from a client.

OnReliabilityFragmentReceived ( object sender, Protogame.MxReliabilityTransmitEventArgs e ) : void

Handle receiving a FragmentReceived event from a reliability class.

OnReliabilityFragmentSent ( object sender, Protogame.MxReliabilityTransmitEventArgs e ) : void

Handle receiving a FragmentSent event from a reliability class.

OnReliabilityMessageAcknowledged ( object sender, Protogame.MxMessageEventArgs e ) : void

Handle receiving a MessageAcknowledged event from a reliability class.

OnReliabilityMessageReceived ( object sender, Protogame.MxMessageEventArgs e ) : void

Handle receiving a MessageReceived event from a reliability class.

ReceiveNonBlocking ( UdpClient client, IPEndPoint &receive ) : byte[]

Receive a message in an non-blocking manner. If there is no message to receive, this function returns null.

RegisterForEvents ( MxClient client ) : void

Register for a client's events.

RegisterForEvents ( MxReliability reliability ) : void

Register for a reliability's events.

ThreadSafeGetOrCreateClient ( IPEndPoint endpoint ) : MxClient
UnregisterFromEvents ( MxClient client ) : void

Unregister from a client's events.

UnregisterFromEvents ( MxReliability reliability ) : void

Unregister from a reliability's events.

Method Details

Close() public method

Closes the dispatcher permanently, terminating all inbound and outbound connections.
public Close ( ) : void
return void

Connect() public method

Explicitly connect to the specified endpoint, assuming there is an Mx dispatcher at the specified address.

This method is used to explicitly add clients, not to start the dispatcher. The dispatcher does not require an explicit start.

public Connect ( IPEndPoint endpoint ) : MxClient
endpoint System.Net.IPEndPoint /// The endpoint to connect to. ///
return MxClient

Disconnect() public method

Disconnects the specified Mx client. This removes it from the group that owns it, and prevents it from reconnecting to this dispatcher implicitly.
public Disconnect ( MxClient client ) : void
client MxClient The client.
return void

Disconnect() public method

Disconnects the entire Mx client group, disconnecting all clients inside it.
public Disconnect ( MxClientGroup clientGroup ) : void
clientGroup MxClientGroup The client group.
return void

GetBytesLastReceivedAndReset() public method

public GetBytesLastReceivedAndReset ( ) : int
return int

GetBytesLastSentAndReset() public method

public GetBytesLastSentAndReset ( ) : int
return int

MxDispatcher() public method

Initializes a new instance of the MxDispatcher class.
public MxDispatcher ( UdpClient client ) : System
client System.Net.Sockets.UdpClient
return System

MxDispatcher() public method

Initializes a new instance of the MxDispatcher class.
public MxDispatcher ( int port ) : System
port int /// The port of the UDP client. ///
return System

OnClientConnected() protected method

Raise the ClientConnected event.
protected OnClientConnected ( MxClient client ) : void
client MxClient /// The client. ///
return void

OnClientDisconnectWarning() protected method

Raise the ClientDisconnectWarning event.
protected OnClientDisconnectWarning ( Protogame.MxDisconnectEventArgs e ) : void
e Protogame.MxDisconnectEventArgs /// The event arguments. ///
return void

OnClientDisconnected() protected method

Raise the ClientDisconnected event.
protected OnClientDisconnected ( MxClient client ) : void
client MxClient /// The client. ///
return void

OnMessageAcknowledged() protected method

Raise the MessageAcknowledged event.
protected OnMessageAcknowledged ( Protogame.MxMessageEventArgs e ) : void
e Protogame.MxMessageEventArgs /// The event arguments. ///
return void

OnMessageLost() protected method

Raise the MessageLost event.
protected OnMessageLost ( Protogame.MxMessageEventArgs e ) : void
e Protogame.MxMessageEventArgs /// The event arguments. ///
return void

OnMessageReceived() protected method

Raise the MessageReceived event.
protected OnMessageReceived ( Protogame.MxMessageEventArgs e ) : void
e Protogame.MxMessageEventArgs /// The event arguments. ///
return void

OnMessageSent() protected method

Raise the MessageSent event.
protected OnMessageSent ( Protogame.MxMessageEventArgs e ) : void
e Protogame.MxMessageEventArgs /// The event arguments. ///
return void

OnReliableReceivedProgress() protected method

Raise the ReliableReceivedProgress event.
protected OnReliableReceivedProgress ( Protogame.MxReliabilityTransmitEventArgs e ) : void
e Protogame.MxReliabilityTransmitEventArgs /// The event arguments. ///
return void

OnReliableSendProgress() protected method

Raise the ReliableSendProgress event.
protected OnReliableSendProgress ( Protogame.MxReliabilityTransmitEventArgs e ) : void
e Protogame.MxReliabilityTransmitEventArgs /// The event arguments. ///
return void

PlaceInGroup() public method

Places the specified Mx client in the specified group.
public PlaceInGroup ( MxClient client, string identifier ) : MxClientGroup
client MxClient The Mx client.
identifier string The group identifier.
return MxClientGroup

Send() public method

Queue a packet for sending to the specified client.
public Send ( MxClient client, byte packet, bool reliable = false ) : void
client MxClient /// The client to send the message to. ///
packet byte /// The associated data to send. ///
reliable bool /// Whether or not this message should be sent reliably and intact. This also /// permits messages larger than 512 bytes to be sent. ///
return void

Send() public method

Queue a packet for sending to the specified endpoint.
public Send ( MxClientGroup group, byte packet, bool reliable = false ) : void
group MxClientGroup /// The group to send the message to. ///
packet byte /// The associated data to send. ///
reliable bool /// Whether or not this message should be sent reliably and intact. This also /// permits messages larger than 512 bytes to be sent. ///
return void

Update() public method

Updates the dispatcher, receiving messages and connecting clients as appropriate.
public Update ( ) : void
return void

this() public method

Retrieves the client group for the given identifier.
public this ( string identifier ) : MxClientGroup
identifier string The identifier for the group.
return MxClientGroup