コード例 #1
0
 /// <summary>
 /// constructor </summary>
 /// <param name='localPort'>The local port to bind to directly on the instanciation, you can specify a port from 1 to 65535, 0  will bind to the first available port, -1 will not bind (you will have to call Bind method manually after instanciation then). Default is -1.</param><c>!Any other value will throw an exception!</c>
 public UDPServer(int localPort = -1)
 {
     _udpManager = new UDPManager(-1);
     _udpManager._udpServerPeers = new List <UDPPeer>();
     _udpManager._InitHiddenChannels();
     _udpManager.AddEventListener <UDPManagerEvent>(UDPManagerEvent.Names.DATA_RECEIVED, _ReceivedDataHandler);
     _udpManager.AddEventListener <UDPManagerEvent>(UDPManagerEvent.Names.DATA_CANCELED, _CancelHandler);
     _udpManager.AddEventListener <UDPManagerEvent>(UDPManagerEvent.Names.DATA_RETRIED, _RetryHandler);
     _udpManager.AddEventListener <UDPManagerEvent>(UDPManagerEvent.Names.DATA_DELIVERED, _DeliveryHandler);
     _udpManager.AddEventListener <UDPClassicMessageEvent>(UDPClassicMessageEvent.Names.MESSAGE, _ClassicDataSystemHandler);
     this._udpManager.AddEventListener <UDPManagerEvent>(UDPManagerEvent.Names.BOUND, this._Listening);
     if (localPort > -1)
     {
         this.Start(localPort);
     }
 }
コード例 #2
0
 /// <summary>
 /// Adds an event listener on the instance that will call the <paramref name="callBack"/> method when an event with the name <paramref name="eventName"/> is dispatched
 /// </summary>
 /// <typeparam name="T">Any type inherited of Event or Event itself</typeparam>
 /// <param name="name">A string that represents the name of the event</param>
 /// <param name="callBack">A method that accepts as unique parameter an instance of the type specified in <typeparamref name="T"/> and that will be called when an event with the name specified in <paramref name="eventName"/> is dispatched</param>
 public void On <T>(object name, Action <T> callBack)
     where T : Event
 {
     udpm.AddEventListener <T>(name, callBack);
 }