예제 #1
0
 public void Start(IEventTemplateDB db, IPEndPoint sendToEP, Action<Socket, IPEndPoint> finishSocket)
 {
     this.TraceData(TraceEventType.Verbose, "EventEmitterBase.ParallelEmitter - Starting");
     _db = db;
     _sendToEP = sendToEP;
     _emitEP = new UdpEndpoint(sendToEP).Initialize(finishSocket);
     _emitterState.SetState(EmitterState.Active);
     this.TraceData(TraceEventType.Verbose, "EventEmitterBase.ParallelEmitter - Started");
 }
예제 #2
0
            /// <summary>
            /// Starts the listener in multi-threaded mode. In this mode the listener
            /// consumes from 1 to 2 threads from the threadpool. A thread is used for
            /// receiving bytes and deserializing LWES events and another thread is 
            /// scheduled to perform event notification only when LWES events have
            /// been received.
            /// </summary>
            /// <param name="db">event template DB used during deserialization</param>
            /// <param name="listenEP">a IP endpoint where listening should occur</param>
            /// <param name="finishSocket"></param>
            /// <param name="listener"></param>
            public void Start(IEventTemplateDB db
                , IPEndPoint listenEP
                , Action<Socket, IPEndPoint> finishSocket
                , EventListenerBase listener)
            {
                this.TraceData(TraceEventType.Verbose, "EventListenerBase.BackgroundThreadListener - Starting");

                _db = db;
                _listener = listener;
                _anyEP = (listenEP.AddressFamily == AddressFamily.InterNetworkV6)
                    ? new IPEndPoint(IPAddress.IPv6Any, listenEP.Port)
                    : new IPEndPoint(IPAddress.Any, listenEP.Port);
                _buffer = BufferManager.AcquireBuffer(null);
                _listenEP = new UdpEndpoint(listenEP).Initialize(finishSocket);
                // Start a dedicated background thread to handle the receiving...
                _reciever = new Thread(Background_Receiver);
                _reciever.IsBackground = true;
                _reciever.Start();

                // Start a dedicated background thread to perform event notification...
                _notifierWaitObject = new Object();
                _notifier = new Thread(Background_Notifier);
                _notifier.IsBackground = true;
                _notifier.Start();

                this.TraceData(TraceEventType.Verbose, () =>
                {
                    return new object[] { String.Concat("EventListenerBase.BackgroundThreadListener - Started state: ", _recieverState.CurrentState) };
                });
            }
예제 #3
0
            /// <summary>
            /// Starts the listener.
            /// </summary>
            /// <param name="db">an event template DB</param>
            /// <param name="listenEP">the listening endpoint</param>
            /// <param name="finishSocket">a callback method that is called upon to finish the listening socket</param>
            /// <param name="owner">the owner</param>
            public void Start(IEventTemplateDB db
                , IPEndPoint listenEP
                , Action<Socket, IPEndPoint> finishSocket
                , EventListenerBase owner)
            {
                this.TraceData(TraceEventType.Verbose, "EventListenerBase.ParallelListener - Starting");

                _db = db;
                _listener = owner;
                _anyEP = (listenEP.AddressFamily == AddressFamily.InterNetworkV6)
                    ? new IPEndPoint(IPAddress.IPv6Any, 0)
                    : new IPEndPoint(IPAddress.Any, 0);

                _receiveQueue = new SimpleLockFreeQueue<ReceiveCapture>();

                _listenEP = new UdpEndpoint(listenEP).Initialize(finishSocket);
                ParallelReceiver();
                this.TraceData(TraceEventType.Verbose, () =>
                {
                    return new object[] { String.Concat("EventListenerBase.ParallelListener - Started state: ", _listenerState.CurrentState) };
                });
            }
예제 #4
0
        static void Main(string[] args)
        {
            /*
             *
             *
             * Usage:
             *    node 127.0.0.1 8000
             *
             * Starts the endpoint on IP address 127.0.0.1 port 8000.
             *
             *
             *
             */

            _Ip   = args[0];
            _Port = Convert.ToInt32(args[1]);

            _UdpEndpoint = new UdpEndpoint(_Ip, _Port);
            _UdpEndpoint.EndpointDetected += EndpointDetected;
            _UdpEndpoint.DatagramReceived += DatagramReceived;
            _UdpEndpoint.StartServer();

            while (true)
            {
                Console.Write("[" + _Ip + ":" + _Port + " Command/? for help]: ");
                string userInput = Console.ReadLine();
                if (String.IsNullOrEmpty(userInput))
                {
                    continue;
                }

                if (userInput.Equals("?"))
                {
                    Menu();
                }
                else if (userInput.Equals("q"))
                {
                    break;
                }
                else if (userInput.Equals("cls"))
                {
                    Console.Clear();
                }
                else if (userInput.Equals("list"))
                {
                    List <string> recents = _UdpEndpoint.Endpoints;
                    if (recents != null)
                    {
                        Console.WriteLine("Recent endpoints");
                        foreach (string endpoint in recents)
                        {
                            Console.WriteLine("  " + endpoint);
                        }
                    }
                    else
                    {
                        Console.WriteLine("None");
                    }
                }
                else
                {
                    string[] parts = userInput.Split(new char[] { ' ' }, 2);
                    if (parts.Length != 2)
                    {
                        continue;
                    }

                    string msg        = parts[1];
                    string ipPort     = parts[0];
                    int    colonIndex = parts[0].LastIndexOf(':');
                    string ip         = ipPort.Substring(0, colonIndex);
                    int    port       = Convert.ToInt32(ipPort.Substring(colonIndex + 1));

                    _UdpEndpoint.Send(ip, port, msg);
                }
            }

            Console.ReadLine();
        }
예제 #5
0
 protected override void OnSent(UdpEndpoint endpoint, long sent)
 {
     // Continue receive datagrams
     ReceiveAsync();
 }
예제 #6
0
 protected override void OnReceived(UdpEndpoint endpoint, byte[] buffer, long size)
 {
     // Echo the message back to the sender
     SendAsync(endpoint, buffer, 0, size);
 }