Esempio n. 1
0
    public static void StartListener(int port)
    {
        print("UDPSend.StartListener()");

        if (listeners == null)
        {
            listeners = new Dictionary <int, UDPListener> ();
        }

        if (!listeners.ContainsKey(port))
        {
            UDPListener newListener = new UDPListener(port);
            listeners.Add(port, newListener);
        }

        if (receiveThreads == null)
        {
            receiveThreads = new List <Thread> ();
        }

        Thread receiveThread = new Thread(
            new ThreadStart(() => ManageListening(listeners[port])));

        receiveThread.IsBackground = true;
        receiveThreads.Add(receiveThread);
        receiveThread.Start();
    }
Esempio n. 2
0
    private void ThreadMethod()
    {
        HandleOscPacket callback = delegate(OscPacket packet)
        {
            var messageReceived = (OscMessage)packet;
            var addr            = messageReceived.Address;
            if (addr == "Person0/elements/alpha_relative")
            {
                for (int i = 0; i < messageReceived.Arguments.Count; i++)
                {
                    alpha[i] = (float)messageReceived.Arguments[i];
                }
            }
            else if (addr == "Person0/elements/beta_relative")
            {
                for (int i = 0; i < messageReceived.Arguments.Count; i++)
                {
                    beta[i] = (float)messageReceived.Arguments[i];
                }
            }
        };

        var listener = new UDPListener(5000, callback);
        // listener.Close();
    }
Esempio n. 3
0
        private static void Listening(object state)
        {
            UDPDuplexListener listener    = (UDPDuplexListener)state;
            UDPListener       udpListener = new UDPListener(new IPEndPoint(IPAddress.Loopback, 13001), 2);

            try
            {
                udpListener.Start();
                if (listener.started != null)
                {
                    listener.started();
                }
                Console.WriteLine("Servidor de áudio iniciado na porta " + udpListener.LocalIPEndPoint.Port.ToString());
                while (true)
                {
                    UDPClient client = udpListener.AcceptClient();
                    listener.clientAccepted(new UDPDuplexCommunication(client));
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine("SocketException: {0}", e);
            }
            finally
            {
                // Stop listening for new clients.
                udpListener.Stop();
            }
        }
Esempio n. 4
0
        private async void Init(PlayerWindow playerWindow)
        {
            var uriString = "http://localhost:8090/tvcontrolapi/";

            this.Host = new NancyHost(new CustomNancyBoostrapper(), new HostConfiguration {
                UrlReservations = new UrlReservations {
                    CreateAutomatically = true
                }
            }, new Uri(uriString));
            this.Host.Start();

            TinyIoCContainer ioc = TinyIoCContainer.Current;

            ioc.AutoRegister();
            ioc.Register <ITasksService>((container, overloads) => new LocalTasksServiceDecorator(new FirebaseTasksService()));

            var playbackControl = new MediaElementPlaybackControl(playerWindow);

            ioc.Register <IPlaybackControl>(playbackControl);
            TvControlViewModel viewModel;

            this.DataContext = playerWindow.DataContext = viewModel = new TvControlViewModel(new TvStations(), playbackControl);

            ioc.Register <ILogger>(viewModel.Log);

            viewModel.Log.Write($"API Running on {uriString}", LogLevel.Info);

            new TasksWindow {
                DataContext = ioc.Resolve <TasksViewModel>()
            }.Show();

            this.udpListener = new UDPListener(11011, s => viewModel.Log.Write(s, LogLevel.Debug));
            await this.udpListener.StartAsync();
        }
        public static void startListenOnSocketAsync(Socket socket, ReceivedPacketCallback callbackLambda)
        {
            UDPListener udpl = delegate()
            {
                try
                {
                    while (true)
                    {
                        IPEndPoint sender             = new IPEndPoint(IPAddress.Any, 0);
                        EndPoint   Remote             = (EndPoint)sender;
                        byte[]     receive_byte_array = new byte[1399];
                        socket.ReceiveFrom(receive_byte_array, ref Remote);
                        sender = (IPEndPoint)Remote;

                        callbackLambda(TCPCopycatPacket.parse(receive_byte_array), sender);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            };
            Task taskA = new Task(() => udpl());

            taskA.Start();
        }
Esempio n. 6
0
        public void setupOSC(int _localPort, string _remoteHost, int _remotePort)
        {
            localPort  = _localPort;
            remoteHost = _remoteHost;
            remotePort = _remotePort;
            if (listener != null)
            {
                listener.Close();
            }

            HandleOscPacket callback = delegate(OscPacket packet)
            {
                var messageReceived = (OscMessage)packet;
                if (messageReceived != null)
                {
                    Console.WriteLine("Received a message! " + messageReceived.Address);
                }
            };

            listener = new UDPListener(localPort, processMessage);

            sender = new UDPSender(remoteHost, remotePort);

            sendCurrentSlide();
            sendTotalSlides();
        }
Esempio n. 7
0
        // Use this for initialization
        protected void Start()
        {
            listener = new UDPListener(port);
            port     = -1;

            //  powerData = new PowerData();
        }
Esempio n. 8
0
        public void TestMessage()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            // Test every message type (except Symbol)
            var msg1 = new SharpOSC.OscMessage(
                "/test/address",

                23,
                42.42f,
                "hello world",
                new byte[3] {
                2, 3, 4
            },
                -123456789123,
                new Timetag(DateTime.Now.Date).Tag,
                new Timetag(DateTime.Now.Date.AddMonths(1)),
                (double)1234567.890,
                new Symbol("wut wut"),
                (char)'x',
                new RGBA(20, 40, 60, 255),
                new Midi(3, 110, 55, 66),
                true,
                false,
                null,
                Double.PositiveInfinity
                );

            OscMessage msgRevc = null;

            sender.Send(msg1);
            msgRevc = (OscMessage)listener.Receive();
            Assert.NotNull(msgRevc);

            Assert.AreEqual("/test/address", msgRevc.Address);
            Assert.AreEqual(16, msgRevc.Arguments.Count);

            Assert.AreEqual(23, msgRevc.Arguments[0]);
            Assert.AreEqual(42.42f, msgRevc.Arguments[1]);
            Assert.AreEqual("hello world", msgRevc.Arguments[2]);
            Assert.AreEqual(new byte[3] {
                2, 3, 4
            }, msgRevc.Arguments[3]);
            Assert.AreEqual(-123456789123, msgRevc.Arguments[4]);
            Assert.AreEqual(new Timetag(DateTime.Now.Date), msgRevc.Arguments[5]);
            Assert.AreEqual(new Timetag(DateTime.Now.Date.AddMonths(1)), msgRevc.Arguments[6]);
            Assert.AreEqual((double)1234567.890, msgRevc.Arguments[7]);
            Assert.AreEqual(new Symbol("wut wut"), msgRevc.Arguments[8]);
            Assert.AreEqual((char)'x', msgRevc.Arguments[9]);
            Assert.AreEqual(new RGBA(20, 40, 60, 255), msgRevc.Arguments[10]);
            Assert.AreEqual(new Midi(3, 110, 55, 66), msgRevc.Arguments[11]);
            Assert.AreEqual(true, msgRevc.Arguments[12]);
            Assert.AreEqual(false, msgRevc.Arguments[13]);
            Assert.AreEqual(null, msgRevc.Arguments[14]);
            Assert.AreEqual(Double.PositiveInfinity, msgRevc.Arguments[15]);

            listener.Close();
        }
Esempio n. 9
0
    void startServer()
    {
        Debug.Log("cs1\n\n");

        HandleOscPacket callback = delegate(OscPacket packet)
        {
            var messageReceived = (OscMessage)packet;
            var addr            = messageReceived.Address;
            if (addr == "/muse/eeg")
            {
                Debug.Log("EEG values: ");
                foreach (var arg in messageReceived.Arguments)
                {
                    Debug.Log(arg + " ");
                }
            }
            if (addr == "/muse/elements/alpha_relative")
            {
                Debug.Log("Relative Alpha power values: ");
                foreach (var arg in messageReceived.Arguments)
                {
                    Debug.Log(arg + " ");
                }
            }
        };

        Debug.Log("cs2\n\n");

        // Create an OSC server.
        var listener = new UDPListener(5000, callback);

        Debug.Log("cs2\n\n");
    }
Esempio n. 10
0
        public void TestCallback()
        {
            bool cbCalled = false;
            // The cabllback function
            HandleOscPacket cb = delegate(OscPacket packet)
            {
                var msg = (OscMessage)packet;
                Assert.AreEqual(2, msg.Arguments.Count);
                Assert.AreEqual(23, msg.Arguments[0]);
                Assert.AreEqual("hello world", msg.Arguments[1]);
                cbCalled = true;
            };

            var l1 = new UDPListener(55555, cb);

            var sender = new SharpOSC.UDPSender("localhost", 55555);
            var msg1 = new SharpOSC.OscMessage("/test/address", 23, "hello world");
            sender.Send(msg1);

            // Wait until callback processes its message
            var start = DateTime.Now;
            while(cbCalled == false && start.AddSeconds(2) > DateTime.Now)
                Thread.Sleep(1);

            Assert.IsTrue(cbCalled);

            l1.Close();
        }
Esempio n. 11
0
        private static void IAmListeningToYou()
        {
            int myport   = 0;
            int yourport = 0;

            List <int> ports = new List <int>();

            IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();

            ipGlobalProperties.GetActiveUdpListeners().ToList().ForEach((t) => ports.Add(t.Port));

            if (!ports.Contains(55555) && !ports.Contains(55556))
            {
                myport   = 55555;
                yourport = 55556;
                Console.WriteLine("'in your presence', callym, 2016.\n");
                Console.WriteLine("the comfort of being silent in your company");
            }
            else if (ports.Contains(55555) && !ports.Contains(55556))
            {
                myport   = 55556;
                yourport = 55555;
            }
            else
            {
                Environment.Exit(0);
            }

            ListeningToYou = new UDPListener(myport, GetMessage);
            ReplyingToYou  = new UDPSender("127.0.0.1", yourport);
        }
Esempio n. 12
0
    void ListenForOtherHosts(UDPListener listener)
    {
        string [] msgParts = listener.lastReceivedUDPPacket.Split('\t');
        IPAddress senderIP = null;

        try
        {
            senderIP = IPAddress.Parse(msgParts[0].ToString());
        }
        catch
        {
        }
        if (senderIP != null && !InterfacesManager.hostIps.Contains(senderIP))
        {
            if (!_knownHosts.ContainsKey(msgParts[0]))
            {
                _knownHosts[msgParts[0]] = new KnownHost(msgParts[0], msgParts[2]);                //"");
            }
            else
            {
                _knownHosts[msgParts[0]].ResetAliveCount();
            }
            Debug.Log("Got message from " + msgParts[0]);
        }
        lastpacket = listener.lastReceivedUDPPacket;
    }
Esempio n. 13
0
        private void btnListen_Click(object sender, EventArgs e)
        {
            if (tbListenPort.Text == "")
            {
                toolStatus.Text = "ERROR: wrong port";
                return;
            }

            int port;

            try
            {
                port = Convert.ToInt32(tbListenPort.Text);
            }
            catch (Exception)
            {
                toolStatus.Text = "ERROR: wrong port";
                return;
            }

            // check that port nr is between 0 and 65535
            if (port < 0 || port > 65535)
            {
                toolStatus.Text = "ERROR: wrong port";
                return;
            }

            UDPListener p = new UDPListener(port);

            toolStatus.Text = "Status: Listening on port " + port.ToString();
        }
Esempio n. 14
0
        static void Main(string[] args)
        {
            Console.WriteLine("Connectando com servidor");
            TCPListener servertcp = new TCPListener("127.0.0.1", 7171, 1024, Server_OnReceiveHandler);

            servertcp.Connect();

            UDPListener server = new UDPListener("192.168.0.100", 7172, 1024, Server_OnReceiveHandler);

            for (int i = 0; i < 10; i++)
            {
                using (ConWriter writer = new ConWriter(0))
                {
                    writer.Send("Teste envia UDP" + i);

                    server.Send(writer);
                }
            }

            string texto = "";

            while (texto != "fim")
            {
                texto = Console.ReadLine();
                ConWriter writer1 = new ConWriter(1);
                writer1.Send(texto);
                Console.WriteLine("Tamanho do buffer: " + writer1._buffer.Length);
                server.Send(writer1);
            }
        }
Esempio n. 15
0
        private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            //开启udp监听负责接收局域网连接用户并添加到分线客户端列表 端口9124
            udpListener = new UDPListener();
            udpListener.onAddMessage += new EventHandler <AddMessageEventArgs>(this.Message);
            udpListener.StartListen();

            //广播分析提醒 端口9114
            SartFind();

            TextBlock1.Text = "正常工作中...";

            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(2000);
                Calculation calculation = new Calculation();
                calculation.Start();
            });

            System.Timers.Timer aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new System.Timers.ElapsedEventHandler(aTimer_Elapsed);
            // 设置引发时间的时间间隔 此处设置为1秒
            aTimer.Interval = 1000;
            aTimer.Enabled  = true;
            aTimer.Start();

            this.Hide();
        }
Esempio n. 16
0
        public void TestByteCallback()
        {
            bool cbCalled = false;
            // The cabllback function
            HandleBytePacket cb = delegate(byte[] packet)
            {
                var msg = (OscMessage)OscPacket.GetPacket(packet);
                Assert.AreEqual(2, msg.Arguments.Count);
                Assert.AreEqual(23, msg.Arguments[0]);
                Assert.AreEqual("hello world", msg.Arguments[1]);
                cbCalled = true;
            };

            var l1 = new UDPListener(55555, cb);

            var sender = new SharpOSC.UDPSender("localhost", 55555);
            var msg1   = new SharpOSC.OscMessage("/test/address", 23, "hello world");

            sender.Send(msg1);

            // Wait until callback processes its message
            var start = DateTime.Now;

            while (cbCalled == false && start.AddSeconds(2) > DateTime.Now)
            {
                Thread.Sleep(1);
            }

            Assert.IsTrue(cbCalled);

            l1.Close();
        }
Esempio n. 17
0
 void ListenForOtherHosts(UDPListener listener)
 {
     string [] msgParts = listener.lastReceivedUDPPacket.Split('\t');
     IPAddress senderIP = null;
     try
     {
          senderIP = IPAddress.Parse(msgParts[0].ToString());
     }
     catch
     {
     }
     if(senderIP != null && !InterfacesManager.hostIps.Contains(senderIP))
     {
         if(!_knownHosts.ContainsKey(msgParts[0]))
         {
             _knownHosts[msgParts[0]] = new KnownHost(msgParts[0], msgParts[2]);//"");
         }
         else
         {
             _knownHosts[msgParts[0]].ResetAliveCount();
         }
         Debug.Log ("Got message from " +msgParts[0]);
     }
     lastpacket = listener.lastReceivedUDPPacket;
 }
    void Start()
    {
        // Callback function for received OSC messages.
        HandleOscPacket callback = delegate(OscPacket packet)
        {
            var messageReceived = (OscMessage)packet;
            var addr            = messageReceived.Address;

            if (addr == "Person0/notch_filtered_eeg")
            {
                /*
                 * Debug.Log("eeg START : ");
                 * foreach(var arg in messageReceived.Arguments) {
                 *      Debug.Log(float.Parse(arg.ToString()) + " ");
                 *
                 * }
                 */


                eeg_data[0] = float.Parse(messageReceived.Arguments[0].ToString());
                eeg_data[1] = float.Parse(messageReceived.Arguments[1].ToString());
                eeg_data[2] = float.Parse(messageReceived.Arguments[2].ToString());
                eeg_data[3] = float.Parse(messageReceived.Arguments[3].ToString());

                //CallbackAcc(eeg_data);
            }
        };

        // Create an OSC server.
        listener = new UDPListener(5005, callback);
        Console.WriteLine("Press enter to stop");
        Console.ReadLine();
    }
Esempio n. 19
0
        static void Main(string[] args)
        {
            Console.WriteLine(" ___    ___ ___   ___  ___      ___ ___  _______   ________          ________  _______   ________  ___      ___ _______   ________     ");
            Console.WriteLine(@"|\  \  /  /|\  \ |\  \|\  \    /  /|\  \|\  ___ \ |\   __  \        |\   ____\|\  ___ \ |\   __  \|\  \    /  /|\  ___ \ |\   __  \    ");
            Console.WriteLine(@"\ \  \/  / | \  \\_\  \ \  \  /  / | \  \ \   __/|\ \  \|\  \       \ \  \___|\ \   __/|\ \  \|\  \ \  \  /  / | \   __/|\ \  \|\  \   ");
            Console.WriteLine(@" \ \    / / \ \______  \ \  \/  / / \ \  \ \  \_|/_\ \   _  _\       \ \_____  \ \  \_|/_\ \   _  _\ \  \/  / / \ \  \_|/_\ \   _  _\  ");
            Console.WriteLine(@"  /     \/   \|_____|\  \ \    / /   \ \  \ \  \_|\ \ \  \\  \|       \|____|\  \ \  \_|\ \ \  \\  \\ \    / /   \ \  \_|\ \ \  \\  \| ");
            Console.WriteLine(@" /  /\   \          \ \__\ \__/ /     \ \__\ \_______\ \__\\ _\         ____\_\  \ \_______\ \__\\ _\\ \__/ /     \ \_______\ \__\\ _\ ");
            Console.WriteLine(@"/__/ /\ __\          \|__|\|__|/       \|__|\|_______|\|__|\|__|       |\_________\|_______|\|__|\|__|\|__|/       \|_______|\|__|\|__|");
            Console.WriteLine(@"|__|/ \|__|                                                            \|_________|                                                    ");

            Task.Factory.StartNew(() =>
            {
                Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "> Iniciando servidor");
                serverUDP = new UDPListener("192.168.0.100", 7172, 1024, Server_OnAcceptHandler, Server_OnReceiveHandler);
                serverUDP.StartServer();

                serverTCP = new TCPListener("192.168.0.100", 7171, 1024, Server_OnAcceptHandler, Server_OnReceiveHandler, Server_OnDisconnectHandler);
                serverTCP.StartServer();

                Console.WriteLine(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "> Servidor iniciado");
            });

            while (Console.ReadLine() != "fim")
            {
            }
            ;
        }
Esempio n. 20
0
        public void ListenerSingleMSG()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            var msg = new SharpOSC.OscMessage("/test/", 23.42f);

            sender.Send(msg);

            while (true)
            {
                var pack = listener.Receive();
                if (pack == null)
                {
                    Thread.Sleep(1);
                }
                else
                {
                    break;
                }
            }

            listener.Dispose();
        }
Esempio n. 21
0
    // start from unity3d
    public void Start()
    {
        UDPListener receiveObj = new UDPListener();

        Thread receiveThread = new Thread(new ThreadStart(() => {
            client = new UdpClient(port);
            while (true)
            {
                try
                {
                    IPEndPoint ip = new IPEndPoint(IPAddress.Any, 0);
                    byte[] data   = client.Receive(ref ip);

                    text = Encoding.UTF8.GetString(data);

                    // print message to console
                    Debug.Log(text);
                }
                catch (Exception e)
                {
                    print(e.ToString());
                }
            }
        }));

        receiveThread.IsBackground = true;
        receiveThread.Start();
    }
 public oscDevice(string name, IPAddress address, int sendPort, int receivePort)
 {
     deviceName = name;
     (input as IDisposable)?.Dispose();             // TODO: I don't need to do this, right?
     (output as IDisposable)?.Dispose();
     input  = new UDPListener(receivePort, parseOSCMessage);
     output = new UDPSender(address.ToString(), sendPort);
 }
Esempio n. 23
0
        public OSCThread(GameObject gameObject, int port)
        {
            listener        = new UDPListener(port);
            this.gameObject = gameObject;

            //listener = new UDPListener(1338, callback);
            Debug.Log("OSCServer started at IP address " + GetLocalIPAddress());
        }
Esempio n. 24
0
 /**
  * Starts the listener for OSC packets on the specified port number and starts the Run function in a new thread
  */
 public override void Start()
 {
     Logger.Log("Starting RemoteOSCAdapter");
     typeMap        = InitTypeMap();
     listener       = new UDPListener(port);
     listenerThread = new Thread(new ThreadStart(Run));
     listenerThread.Start();
 }
Esempio n. 25
0
 private void StartUDPListener()
 {
     if (UDPListener == null)
     {
         UDPListener = new UDPListener();
         UDPListener.DeviceNotificationRecieved += HandleUDP;
         UDPListener.StartListener(Musiccast.Model.Constants.UDP_ListenPort);
     }
 }
Esempio n. 26
0
        /// <summary>
        /// EVENT HANDLERS
        /// </summary>

        // Subscribe to UDP listener events
        public void subscribeToListener(UDPListener l)
        {
            l.receiveRequestTable   += new UDPListener.handlerRequestTable(handleRequestTable);
            l.receiveTable          += new UDPListener.handlerTable(handleTable);
            l.receiveClosest        += new UDPListener.handlerFindChannel(handleReceiveClosest);
            l.receiveRequestClosest += new UDPListener.handlerRequestClosest(handleRequestClosest);
            l.receiveRequestJoin    += new UDPListener.handlerRequestJoin(handleJoinRequest);
            l.receiveRequestLeave   += new UDPListener.handlerRequestLeave(handleLeaveRequest);
        }
Esempio n. 27
0
        private void done_option_Click(object sender, EventArgs e)
        {
            ParentForm.Hide();
            IListener udplistener = new UDPListener(textAddr.Text, int.Parse(waterMarkTextBox1.Text));
            ISender   udpsender   = new UDPSender(textAddr.Text, int.Parse(waterMarkTextBox1.Text));
            GameArea  game        = new GameArea(ParentForm, udplistener, udpsender);

            game.Show();
        }
Esempio n. 28
0
        static void Main(string[] args)
        {
            var udp = new UDPListener();

            udp.ReceiveRequest += UdpReceiveRequest;
            var listenerThread = new Thread(udp.StartListener);

            listenerThread.Start();
        }
Esempio n. 29
0
    // Use this for initialization
    void Start()
    {
        rigidbody       = GetComponent <Rigidbody> ();
        messageReceived = null;
        listener        = new UDPListener(55555);

        boxcollider         = GetComponent <BoxCollider>();
        boxcollider.enabled = false;
    }
Esempio n. 30
0
        public void TestMessage()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            // Test every message type (except Symbol)
            var msg1 = new SharpOSC.OscMessage(
                "/test/address",

                23,
                42.42f,
                "hello world",
                new byte[3] { 2, 3, 4 },
                -123456789123,
                new Timetag(DateTime.Now.Date).Tag,
                new Timetag(DateTime.Now.Date.AddMonths(1)),
                (double)1234567.890,
                new Symbol("wut wut"),
                (char)'x',
                new RGBA(20, 40, 60, 255),
                new Midi(3, 110, 55, 66),
                true,
                false,
                null,
                Double.PositiveInfinity
            );

            OscMessage msgRevc = null;

            sender.Send(msg1);
            msgRevc = (OscMessage)listener.Receive();
            Assert.NotNull(msgRevc);

            Assert.AreEqual("/test/address", msgRevc.Address);
            Assert.AreEqual(16, msgRevc.Arguments.Count);

            Assert.AreEqual(23,												msgRevc.Arguments[0]);
            Assert.AreEqual(42.42f,											msgRevc.Arguments[1]);
            Assert.AreEqual("hello world",									msgRevc.Arguments[2]);
            Assert.AreEqual(new byte[3] { 2, 3, 4 },						msgRevc.Arguments[3]);
            Assert.AreEqual(-123456789123,									msgRevc.Arguments[4]);
            Assert.AreEqual(new Timetag(DateTime.Now.Date),					msgRevc.Arguments[5]);
            Assert.AreEqual(new Timetag(DateTime.Now.Date.AddMonths(1)),	msgRevc.Arguments[6]);
            Assert.AreEqual((double)1234567.890,							msgRevc.Arguments[7]);
            Assert.AreEqual(new Symbol("wut wut"),							msgRevc.Arguments[8]);
            Assert.AreEqual((char)'x',										msgRevc.Arguments[9]);
            Assert.AreEqual(new RGBA(20, 40, 60, 255),						msgRevc.Arguments[10]);
            Assert.AreEqual(new Midi(3, 110, 55, 66),						msgRevc.Arguments[11]);
            Assert.AreEqual(true,											msgRevc.Arguments[12]);
            Assert.AreEqual(false,											msgRevc.Arguments[13]);
            Assert.AreEqual(null,											msgRevc.Arguments[14]);
            Assert.AreEqual(Double.PositiveInfinity,						msgRevc.Arguments[15]);

            listener.Close();
        }
Esempio n. 31
0
    // Use this for initialization

    void Start()
    {
        //Debug.Log("ayyysdasd");
        listener = new UDPListener(12003, handleOSC);

        powerData = new PowerData();
        //filename = Application.dataPath + "/PowerLog/AlphaLog/"+ GameManager.instance.settings.subjectName+ "_" + DateTime.Now.ToFileTimeUtc() + ".csv";
        //Debug.Log(Application.dataPath);
        writeHeader();
    }
        /// <summary>
        ///
        /// </summary>
        void StartListening()
        {
            UDPListener listener = new UDPListener(this);

            listener.Start();

            Console.ReadKey();

            listener.Stop();
        }
Esempio n. 33
0
        public void CloseListener()
        {
            var l1 = new UDPListener(55555);
            var isnull = l1.Receive();
            l1.Close();

            var l2 = new UDPListener(55555);
            isnull = l2.Receive();
            l2.Close();
        }
Esempio n. 34
0
        private async Task StartListeningAsync(object sender)
        {
            if (UDPListener == null)
            {
                UDPListener = new UDPListener(20777);
                UDPListener.BytesReceived += UDPListener_BytesReceived;
            }

            var senderButton = sender as Button;

            if (IsListening)
            {
                senderButton.Content = "Start Listening";
                StopListening();
            }
            else
            {
                senderButton.Content = "Stop Listening";
                await StartListening().ConfigureAwait(false);
            }

            async Task StartListening()
            {
                GraphRenderTimer.Start();
                IsListening = true;

                ResetCurrentTelemetryIndexCursor();

                try
                {
                    ListeningCancellationTokenSource = new CancellationTokenSource();

                    await Task.Run(() =>
                    {
                        while (IsListening)
                        {
                            UDPListener.Listen();
                        }
                    }, ListeningCancellationTokenSource.Token);
                }
                finally
                {
                    UDPListener.Close();
                    UDPListener = null;
                }
            }

            void StopListening()
            {
                UDPListener.Close();
                ListeningCancellationTokenSource.Cancel();
                GraphRenderTimer.Stop();
                IsListening = false;
            }
        }
Esempio n. 35
0
 public static void ManageListening(UDPListener listener)
 {
     listener.receivedMsg = true;
     while (keepListening)
     {
         if(listener.receivedMsg)
         {
             mutex.WaitOne ();
             listener.receivedMsg = false;
             mutex.ReleaseMutex();
             listener.client.BeginReceive(new AsyncCallback(Listen), listener);
         }
     }
     Debug.Log ("Quitting listener");
 }
Esempio n. 36
0
        public void CloseListenerException()
        {
            UDPListener l1 = null;
            bool ex = false;
            try
            {
                l1 = new UDPListener(55555);
                var isnull = l1.Receive();
                var l2 = new UDPListener(55555);
            }
            catch (Exception e)
            {
                ex = true;
            }

            Assert.IsTrue(ex);
            l1.Close();
        }
Esempio n. 37
0
        public void ListenerLoadTest()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            var msg = new SharpOSC.OscMessage("/test/", 23.42f);

            for (int i = 0; i < 1000; i++)
                sender.Send(msg);

            for (int i = 0; i < 1000; i++)
            {
                var receivedMessage = listener.Receive();
                Assert.NotNull(receivedMessage);
            }

            listener.Dispose();
        }
Esempio n. 38
0
        public void ListenerSingleMSG()
        {
            var listener = new UDPListener(55555);

            var sender = new SharpOSC.UDPSender("localhost", 55555);

            var msg = new SharpOSC.OscMessage("/test/", 23.42f);

            sender.Send(msg);

            while (true)
            {
                var pack = listener.Receive();
                if (pack == null)
                    Thread.Sleep(1);
                else
                    break;
            }

            listener.Dispose();
        }
Esempio n. 39
0
        public void TestBundle()
        {
            var listener = new UDPListener(55555);

            var sender1 = new SharpOSC.UDPSender("localhost", 55555);
            var msg1 = new SharpOSC.OscMessage("/test/address1", 23, 42.42f, "hello world", new byte[3] { 2, 3, 4 });
            var msg2 = new SharpOSC.OscMessage("/test/address2", 34, 24.24f, "hello again", new byte[5] { 5, 6, 7, 8, 9 });
            var dt = DateTime.Now;
            var bundle = new SharpOSC.OscBundle(Utils.DateTimeToTimetag(dt), msg1, msg2);

            sender1.Send(bundle);
            sender1.Send(bundle);
            sender1.Send(bundle);

            var recv = (OscBundle)listener.Receive();
            recv = (OscBundle)listener.Receive();
            recv = (OscBundle)listener.Receive();

            Assert.AreEqual(dt.Date, recv.Timestamp.Date);
            Assert.AreEqual(dt.Hour, recv.Timestamp.Hour);
            Assert.AreEqual(dt.Minute, recv.Timestamp.Minute);
            Assert.AreEqual(dt.Second, recv.Timestamp.Second);
            //Assert.AreEqual(dt.Millisecond, recv.DateTime.Millisecond); Ventus not accurate enough

            Assert.AreEqual("/test/address1", recv.Messages[0].Address);
            Assert.AreEqual(4, recv.Messages[0].Arguments.Count);
            Assert.AreEqual(23, recv.Messages[0].Arguments[0]);
            Assert.AreEqual(42.42f, recv.Messages[0].Arguments[1]);
            Assert.AreEqual("hello world", recv.Messages[0].Arguments[2]);
            Assert.AreEqual(new byte[3] { 2, 3, 4 }, recv.Messages[0].Arguments[3]);

            Assert.AreEqual("/test/address2", recv.Messages[1].Address);
            Assert.AreEqual(4, recv.Messages[1].Arguments.Count);
            Assert.AreEqual(34, recv.Messages[1].Arguments[0]);
            Assert.AreEqual(24.24f, recv.Messages[1].Arguments[1]);
            Assert.AreEqual("hello again", recv.Messages[1].Arguments[2]);
            Assert.AreEqual(new byte[5] { 5, 6, 7, 8, 9 }, recv.Messages[1].Arguments[3]);

            listener.Close();
        }
Esempio n. 40
0
        static void Main(string[] args)
        {
            /*var message = new SharpOSC.OscMessage("/Knob", 0.5f);
            var sender = new SharpOSC.UDPSender("127.0.0.1", 10000);

            while (true)
            {
                var inp = Console.ReadLine();
                float f = Convert.ToSingle(inp);
                message.Arguments[0] = f;
                sender.Send(message);
            }*/

            HandleOscPacket cb = delegate(OscPacket packet)
            {
                var msg = ((OscBundle)packet).Messages[0];
                Console.WriteLine(msg.Arguments[0].ToString());
            };

            var l1 = new UDPListener(10001, cb);

            Console.ReadLine();
        }
Esempio n. 41
0
    void Start()
    {
        //Init some reference holders
        playerName = UnityEngine.SystemInfo.deviceName;
        _knownHosts = new Dictionary<string, KnownHost> ();
        InterfacesManager.InitInterfacesList();

        //Init Broadcast send and receive channels
        UDPBroadCast.CreateUDPBroadcastManager (defaultBroadcastPort);
        UDPReceiveManager.StartListener (defaultBroadcastPort);
        broadcastListener = UDPReceiveManager.GetActiveListeners () [defaultBroadcastPort];

        //Initiate periodic alive message
        SendAlive ();
    }
 void Start()
 {
     UDPListener listener = new UDPListener(1337);
     listener.Listen();
 }
Esempio n. 43
0
    /*********************************************************************************/
    /*********************************************************************************/
    // Listener thread init and management functions
    public static void StartListener(int port, IPAddress ip)
    {
        print("UDPSend.StartListener()");

        if(listeners == null)
            listeners = new Dictionary<int, UDPListener> ();

        if(!listeners.ContainsKey(port))
        {
            UDPListener newListener = new UDPListener (port, ip);
            listeners.Add (port, newListener);
        }

        if (receiveThreads == null)
            receiveThreads = new List<Thread> ();

        Thread receiveThread = new Thread(
            new ThreadStart(() => ManageListening(listeners[port])));
        receiveThread.IsBackground = true;
        receiveThreads.Add (receiveThread);
        receiveThread.Start();
    }