Example #1
0
        protected override IConnectFuture Connect(Int32 port, IoHandler handler)
        {
            IoConnector connector = new AsyncDatagramConnector();

            connector.Handler = handler;
            return(connector.Connect(new IPEndPoint(IPAddress.Loopback, port)));
        }
Example #2
0
        static void StartMulticastConnector()
        {
            IPAddress localIPAddr = IPAddress.Any;
            IPEndPoint mcastEP = new IPEndPoint(mcastAddress, mcastPort);
            AsyncDatagramConnector connector = new AsyncDatagramConnector();

            connector.FilterChain.AddLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Encoding.UTF8)));

            // Set the local IP address used by the listener and the sender to 
            // exchange multicast messages. 
            connector.DefaultLocalEndPoint = new IPEndPoint(localIPAddr, 0);

            // Define a MulticastOption object specifying the multicast group  
            // address and the local IP address. 
            // The multicast group address is the same as the address used by the listener.
            MulticastOption mcastOption = new MulticastOption(mcastAddress, localIPAddr);
            connector.SessionConfig.MulticastOption = mcastOption;

            // Call Connect() to force binding to the local IP address,
            // and get the associated multicast session.
            IoSession session = connector.Connect(mcastEP).Await().Session;

            // Send multicast packets to the multicast endpoint.
            session.Write("hello 1", mcastEP);
            session.Write("hello 2", mcastEP);
            session.Write("hello 3", mcastEP);
        }
Example #3
0
        static void Main(string[] args)
        {
            IoConnector connector = new AsyncDatagramConnector();

            connector.ExceptionCaught += (s, e) =>
            {
                Console.WriteLine(e.Exception);
            };
            connector.MessageReceived += (s, e) =>
            {
                Console.WriteLine("Session recv...");
            };
            connector.MessageSent += (s, e) =>
            {
                Console.WriteLine("Session sent...");
            };
            connector.SessionCreated += (s, e) =>
            {
                Console.WriteLine("Session created...");
            };
            connector.SessionOpened += (s, e) =>
            {
                Console.WriteLine("Session opened...");
            };
            connector.SessionClosed += (s, e) =>
            {
                Console.WriteLine("Session closed...");
            };
            connector.SessionIdle += (s, e) =>
            {
                Console.WriteLine("Session idle...");
            };

            IConnectFuture connFuture = connector.Connect(new IPEndPoint(IPAddress.Loopback, MemoryMonitor.port));
            connFuture.Await();

            connFuture.Complete += (s, e) =>
            {
                IConnectFuture f = (IConnectFuture)e.Future;
                if (f.Connected)
                {
                    Console.WriteLine("...connected");
                    IoSession session = f.Session;

                    for (int i = 0; i < 30; i++)
                    {
                        Int64 memory = GC.GetTotalMemory(false);
                        IoBuffer buffer = IoBuffer.Allocate(8);
                        buffer.PutInt64(memory);
                        buffer.Flip();
                        session.Write(buffer);

                        try
                        {
                            Thread.Sleep(1000);
                        }
                        catch (ThreadInterruptedException)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Not connected...exiting");
                }
            };

            Console.ReadLine();
        }
Example #4
0
        public void Start()
        {
            IPEndPoint ep = new IPEndPoint(locator.SocketAddress, locator.Port);
            bool isMultiCastAddr;
            if (ep.AddressFamily == AddressFamily.InterNetwork) //IP v4
            {
                byte byteIp = ep.Address.GetAddressBytes()[0];
                isMultiCastAddr = (byteIp >= 224 && byteIp < 240) ? true : false;
            }
            else if (ep.AddressFamily == AddressFamily.InterNetworkV6)
            {
                isMultiCastAddr = ep.Address.IsIPv6Multicast;
            }
            else
            {
                throw new NotImplementedException("Address family not supported yet: " + ep.AddressFamily);
            }

            connector = new AsyncDatagramConnector();

            connector.FilterChain.AddLast("RTPS", new ProtocolCodecFilter(new MessageCodecFactory()));

            if (isMultiCastAddr)
            {
                // Set the local IP address used by the listener and the sender to 
                // exchange multicast messages. 
                connector.DefaultLocalEndPoint = new IPEndPoint(IPAddress.Any, 0);

                // Define a MulticastOption object specifying the multicast group  
                // address and the local IP address. 
                // The multicast group address is the same as the address used by the listener.
                MulticastOption mcastOption = new MulticastOption(locator.SocketAddress, IPAddress.Any);
                connector.SessionConfig.MulticastOption = mcastOption;

                // Call Connect() to force binding to the local IP address,
                // and get the associated multicast session.
                IoSession session = connector.Connect(ep).Await().Session;
            }

            connector.ExceptionCaught += (s, e) =>
            {
                log.Error(e.Exception);
            };
            connector.MessageReceived += (s, e) =>
            {
                log.Debug("Session recv...");
            };
            connector.MessageSent += (s, e) =>
            {
                log.Debug("Session sent...");
            };
            connector.SessionCreated += (s, e) =>
            {
                log.Debug("Session created...");
            };
            connector.SessionOpened += (s, e) =>
            {
                log.Debug("Session opened...");
            };
            connector.SessionClosed += (s, e) =>
            {
                log.Debug("Session closed...");
            };
            connector.SessionIdle += (s, e) =>
            {
                log.Debug("Session idle...");
            };
            IConnectFuture connFuture = connector.Connect(new IPEndPoint(locator.SocketAddress, locator.Port));
            connFuture.Await();

            connFuture.Complete += (s, e) =>
            {
                IConnectFuture f = (IConnectFuture)e.Future;
                if (f.Connected)
                {
                    log.Debug("...connected");
                    session = f.Session;
                }
                else
                {
                    log.Warn("Not connected...exiting");
                }
            };
        }
 protected override IConnectFuture Connect(Int32 port, IoHandler handler)
 {
     IoConnector connector = new AsyncDatagramConnector();
     connector.Handler = handler;
     return connector.Connect(new IPEndPoint(IPAddress.Loopback, port));
 }
Example #6
0
 public void SetUp()
 {
     acceptor  = new AsyncDatagramAcceptor();
     connector = new AsyncDatagramConnector();
 }
 public void SetUp()
 {
     acceptor = new AsyncDatagramAcceptor();
     connector = new AsyncDatagramConnector();
 }