Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
        // Start is called before the first frame update
        void Start()
        {
            udpm = new _UDPManager();
            udpm.DefaultTarget = this;

            //Add listeners on the instance of UDPManager
            udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.BOUND, (UDPManagerEvent e) =>
            {
                listeners.OnBound?.Invoke(e);
            });
            udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_CANCELED, (UDPManagerEvent e) =>
            {
                listeners.OnDataCanceled?.Invoke(e);
            });
            udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_DELIVERED, (UDPManagerEvent e) =>
            {
                listeners.OnDataDelivered?.Invoke(e);
            });
            udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_RECEIVED, (UDPManagerEvent e) =>
            {
                listeners.OnDataReceived?.Invoke(e);
            });
            udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_RETRIED, (UDPManagerEvent e) =>
            {
                listeners.OnDataRetried?.Invoke(e);
            });
            udpm.On <UDPManagerEvent>(UDPManagerEvent.Names.DATA_SENT, (UDPManagerEvent e) =>
            {
                listeners.OnDataSent?.Invoke(e);
            });

            channels.ForEach((UChannel uc) =>
            {
                udpm.AddChannel(uc.Name, uc.GuarantiesDelivery, uc.MaintainOrder, uc.RetryTime, uc.CancelTime);
            });

            udpm.Bind(port);
        }