Inheritance: IDisposable
    void InitiateConnection()
    {
        // initialize the sender: easy!
        mySender = new SharpOSC.UDPSender(myAddress.Address.ToString(), myAddress.Port);

        // initialize the listener: create a callback to route messages
        SharpOSC.HandleOscPacket listenerCallback = delegate(SharpOSC.OscPacket packet)
        {
            // get message
            SharpOSC.OscMessage messageReceived = (SharpOSC.OscMessage)packet;

            // send message along to be processed on the main thread in Update()
            myOSCIncomingMessages.Enqueue(Tuple.Create(messageReceived.Address, messageReceived.Arguments));
        };

        // initialize the listener
        myListener = new SharpOSC.UDPListener(myAddress.Port, listenerCallback);


        // tell the other side we exist
        SendMessage("/___broadcastToMePlease___", GetMyIP());
    }
Beispiel #2
0
    void Start()
    {
        // start discoverability, telling people who know discoveryIdentifier about OSCPort
        myBeacon            = new BeaconLib.Beacon(discoveryIdentifier, OSCPort);
        myBeacon.BeaconData = "";
        myBeacon.Start();

        // start OSC listener on port OSCPort
        // define the callback
        SharpOSC.HandleOscPacket listenerCallback = delegate(SharpOSC.OscPacket packet)
        {
            // get message
            SharpOSC.OscMessage messageReceived = (SharpOSC.OscMessage)packet;

            // send message along to be processed on the main thread in Update()
            myOSCIncomingMessages.Enqueue(Tuple.Create(messageReceived.Address, messageReceived.Arguments));
        };

        // tell the callback our hidden action
        ListenForMessage("/___broadcastToMePlease___", RespondToNewListener);

        // set up the callback
        myListener = new SharpOSC.UDPListener(OSCPort, listenerCallback);
    }
Beispiel #3
0
        public void start()
        {
            // The video cabllback function
            HandleOscPacket callback = delegate(OscPacket packet)
            {
                var messageReceived = (OscMessage)packet;
                String message = messageReceived.Arguments[0].ToString();
                VideoPacket videoPacket = (VideoPacket)Serializer.StringToObject(message);
                model.addVideoPacket(videoPacket);
                print(videoPacket.ToString());
                print("Video Affect Recieved!");
            };

            videolistener = new UDPListener(55555, callback);

            // Audio Reciever
            HandleOscPacket Audiocallback = delegate(OscPacket packet)
            {
                var messageReceived = (OscMessage)packet;

                if (messageReceived.Address == "/general/totaltime")
                {
                    //updateAudiopacket("PersonA", 0.0, Convert.ToDouble(messageReceived.Arguments[0]), 0, 0.0);
                    //updateAudiopacket("PersonB", 0.0, Convert.ToDouble(messageReceived.Arguments[0]), 0, 0.0);
                    audioPackets[0].totalTime = Convert.ToDouble(messageReceived.Arguments[0]);
                    audioPackets[1].totalTime = Convert.ToDouble(messageReceived.Arguments[0]);
                }
                else
                {
                    if (messageReceived.Address == "/speaker1/volume")
                    {
                        //updateAudiopacket(0, 0.0, 0.0, 0, Convert.ToDouble(messageReceived.Arguments[0]));
                        audioPackets[0].maxValue = Convert.ToDouble(messageReceived.Arguments[0]);
                    }
                    if (messageReceived.Address == "/speaker2/volume")
                    {
                        //updateAudiopacket(1, 0.0, 0.0, 0, Convert.ToDouble(messageReceived.Arguments[0]));
                        audioPackets[1].maxValue = Convert.ToDouble(messageReceived.Arguments[0]);
                    }
                    if (messageReceived.Address == "/speaker1/interrupts")
                    {
                        //updateAudiopacket(0, 0.0, 0.0, Convert.ToInt32(messageReceived.Arguments[0]), 0.0);
                        audioPackets[0].numberOfInterruptions = Convert.ToInt32(messageReceived.Arguments[0]);
                    }
                    if (messageReceived.Address == "/speaker2/interrupts")
                    {
                        //updateAudiopacket(1, 0.0, 0.0, Convert.ToInt32(messageReceived.Arguments[0]), 0.0);
                        audioPackets[1].numberOfInterruptions = Convert.ToInt32(messageReceived.Arguments[0]);
                    }
                    if (messageReceived.Address == "/speaker1/talktime")
                    {
                        //updateAudiopacket(0, Convert.ToDouble(messageReceived.Arguments[0]), 0.0, 0, 0.0);
                        audioPackets[0].individualsTime = Convert.ToDouble(messageReceived.Arguments[0]);
                    }
                    if (messageReceived.Address == "/speaker2/talktime")
                    {
                        //updateAudiopacket(1, Convert.ToDouble(messageReceived.Arguments[0]), 0.0, 0, 0.0);
                        audioPackets[1].individualsTime = Convert.ToDouble(messageReceived.Arguments[0]);
                    }
                    for (int i = 0; i < audioPackets.Count; i++)
                    {
                        if (audioPackets[i].isFinished())
                        {
                            model.addAudioPacket(audioPackets[i]);
                            int person = audioPackets[i].person;
                            print(audioPackets[i].ToString());
                            audioPackets[i] = new AudioPacket(person);
                        }
                    }
                }

            };

            audiolistener = new UDPListener(55556, Audiocallback);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            // The IP address of the server (the PC on which this program is running)
            string sHostIpAddress = "128.2.102.159";
            // Standard port number
            int nPort = 21;

            Console.WriteLine("Opening IP Address: " + sHostIpAddress);
            IPAddress ipAddress = IPAddress.Parse(sHostIpAddress);        // Create the IP address
            Console.WriteLine("Starting to listen on port: " + nPort);
            TcpListener tcpListener = new TcpListener(ipAddress, nPort);  // Create the tcp Listener
            tcpListener.Start();                                          // Start listening

            // Set up OSC
            // Let the user set the IP Address and Port for sending out OSC info
            Console.WriteLine("Enter IP Address of Remote Computer receiving data: ");
            String oscIP = Console.ReadLine();
            Console.WriteLine("Enter PORT of Remote Computer receiving data: ");
            String oscPORT = Console.ReadLine();

            // offer a use a default IP / PORT
            if (oscIP.Length == 0 && oscPORT.Length == 0)
            {
                oscIP = "128.237.191.176";
                oscPORT = "55555";
                Console.WriteLine("...Set to default IP and PORT: " + oscIP + ":" + oscPORT);

            }

            // Setup OSC sender to remote computer
            var sender = new SharpOSC.UDPSender(oscIP, Int32.Parse(oscPORT));// "10.140.76.75", 55555);

            Console.WriteLine();
            Console.WriteLine("Ready to Stream!");
            Console.WriteLine("+ + + + + + + + + + + + ");

            // Setup OSC listener
            HandleOscPacket callback = delegate(OscPacket packet)
            {
                var oscMsg = (OscMessage)packet;

                String addr = oscMsg.Address;
                if (addr.Equals("/pose"))
                    OSCinput = "getTcpPose";
                else if (addr.Equals("/target"))
                    OSCinput = "getTargetPose";
                else if (addr.Equals("/joints"))
                    OSCinput = "getJointPose";
                else if (addr.Equals("/force"))
                    OSCinput = "getForce";
                else if (addr.Equals("/tcpForce"))
                    OSCinput = "getTcpForce";
                else if (addr.Equals("/movej"))
                {
                    OSCinput = "movej";
                    // print out the incoming osc message
                    //Console.WriteLine(addr);
                    for (int i = 0; i < oscMsg.Arguments.Count; i++)
                    {
                        pose[i] = float.Parse(oscMsg.Arguments[i].ToString());
                    //    Console.WriteLine("     " + pose[i]);
                    }
                    //Console.WriteLine("");
                }

            };

            var listener = new UDPListener(12000, callback);

            // Keep on listening forever
            while (true)
            {
                TcpClient tcpClient = tcpListener.AcceptTcpClient();        // Accept the client
                Console.WriteLine("Accepted new client");
                NetworkStream stream = tcpClient.GetStream();               // Open the network stream
                while (tcpClient.Client.Connected)
                {

                    // Console.Write("Send msg to Robot OVER OSC: ");
                    // string input = Console.ReadLine();

                    // if we've gotten an OSC message
                    if (!OSCinput.Equals(""))
                    {
                        sendMsg(stream, OSCinput);

                        string msg = "";
                        while (msg.Equals(""))
                        {
                            msg = receiveMsg(stream, tcpClient, sender);
                        }

                        // if we are sending an additional command
                        if (OSCinput.Equals("movej"))
                        {

                            string poseMsg = "(";
                            for (int i = 0; i < 6; i++)
                            {
                                poseMsg += pose[i];
                                if (i < 5)
                                    poseMsg += ", ";
                                else
                                    poseMsg += ")";
                            }
                            Console.WriteLine(poseMsg);
                            sendMsg(stream, poseMsg);
                        }

                        // reset the OSC input
                        OSCinput = "";
                    }

                }
            }

            //listener.Close();
        }