Skip to content

cccda63c a26d 7de9 42e0 634381b5a99d

Arthur Frederico Neves edited this page Jul 19, 2016 · 6 revisions

Protocol(TPack) Class

Responsible for managing a communication protocol, in other words, analyze an incoming packet, check for a method of treatment registered for that type of package, if any, the method is called to handle the package, if not a generic event is called to handle the incoming pack. Idealised to facilitate handling packages and management protocols, especially in cases where the client continuously migrates between different protocols.

Inheritance Hierarchy

System.Object
  NETLIB.Protocol(TPack)
Namespace: NETLIB
Assembly: NETLIB (in NETLIB.dll) Version: 1.0.0.0 (1.0.0.0)

Syntax

C#

public class Protocol<TPack>
where TPack : BasePack

VB

Public Class Protocol(Of TPack As BasePack)

C++

generic<typename TPack>
where TPack : BasePack
public ref class Protocol

F#

type Protocol<'TPack when 'TPack : BasePack> =  class end

Type Parameters

 

TPack
Pack class derived from BasePack that the Protocol will manage.
  The Protocol(TPack) type exposes the following members.

Constructors

 

Name Description
Public method Protocol(TPack)(String) initializes the Protocol with a empty dictionary of codes.
Public method Protocol(TPack)(String, ThrowPackEventHandler(TPack)[]) initializes the Protocol with a existing dictionary of methods.
  Back to Top

Properties

 

Name Description
Public property Item Gets the method reletad to a specific ID.
Public property Name Name used to identify this protocol.
Public property Triggers Dictionary of methods used to bind a method of treating to particular ID. Must have 256 or fewer positions because the package ID is represented by a byte.
  Back to Top

Methods

 

Name Description
Public method AddTrigger Add a method that will be called when the pack's ID is equal 'Key'.
Public method ClearTriggers Clear all the triggers.
Public method Equals Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as the default hash function. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method OnReceivedPackCall Function used to call the method referring to a specific ID
Public method RemoveTrigge Remove all triggers for a particular ID.
Public method SetTriggers Set a new dictionary of methods.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
  Back to Top

Events

 

Name Description
Public event ReceivedPack Generic method used to treat packets without associated methods.
  Back to Top

Examples

The following example code shows how to instantiate a new Protocol(TPack) and how to configure the handler methods

public void CreateProtocolExampleMethod()
{
    var newProtocol = new Protocol<BasePack>("newProtocol");
    newProtocol[0] += ZeroIDHandler;
    bewProtocol.ReceivedPack += DefaultIDHundler;
}

private static void ZeroIDHandler(Consumer<BasePack> consumer, BasePack receivedPack)
{
    //Do something with the packets that have ID = 0.
}

private static void DefaultIDHundler(Consumer<BasePack> consumer, BasePack receivedPack)
{
    //Do something with the packets that do not have a handler method registered.
}

See Also

Reference

NETLIB Namespace

Clone this wiki locally