Ejemplo n.º 1
0
    OSCClient CreateOSCClient(string ip, int port)
    {
        var client = new OSCClient(System.Net.IPAddress.Parse(ip), port);

        client.Connect();
        return(client);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Creates an OSC Client (sends OSC messages) given an outgoing port and address.
    /// </summary>
    /// <param name="clientId">
    /// A <see cref="System.String"/>
    /// </param>
    /// <param name="destination">
    /// A <see cref="IPAddress"/>
    /// </param>
    /// <param name="port">
    /// A <see cref="System.Int32"/>
    /// </param>
    public void CreateClient(string clientId, IPAddress destination, int port)
    {
        if (m_DebugCreateNoServers)
        {
            return;
        }

        OSCClient newOSCClient = new OSCClient(destination, port);

        m_Clients.Add(newOSCClient);

        // Send test message
        string     testaddress = "/test/alive/";
        OSCMessage message     = new OSCMessage(testaddress, destination.ToString());

        message.Append(port); message.Append("OK");

        //_clients[clientId].log.Add(String.Concat(DateTime.UtcNow.ToString(),".",
        //                                         FormatMilliseconds(DateTime.Now.Millisecond), " : ",
        //                                         testaddress," ", DataToString(message.Data)));
        //_clients[clientId].messages.Add(message);
        newOSCClient.Send(message);

        Debug.Log("Client created. " + clientId + ", " + destination.ToString() + ", " + port.ToString() + " Client count: " + m_Clients.Count);
    }
Ejemplo n.º 3
0
	// Use this for initialization
	void Awake ()
	{
		client = new OSCClient (IPAddress.Parse (Host), port + droneIndex);
		Time.maximumDeltaTime = 0.1f;
		int count = UniMoveController.GetNumConnected();
		Debug.Log (count);
		// Iterate through all connections (USB and Bluetooth)
		if (moves.Count == 0) {
			for (int i = 0; i < count; i++) {
				UniMoveController move = gameObject.AddComponent<UniMoveController> ();  // It's a MonoBehaviour, so we can't just call a constructor
			
				// Remember to initialize!
				if (!move.Init (i)) {
					Destroy (move);  // If it failed to initialize, destroy and continue on
					continue;
				}
			
				// This example program only uses Bluetooth-connected controllers
				PSMoveConnectionType conn = move.ConnectionType;
				if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB) {
					Destroy (move);
				} else {
					moves.Add (move);
					move.OnControllerDisconnected += HandleControllerDisconnected;
				}
			}
		}
	}
Ejemplo n.º 4
0
        IEnumerator RepeatHandshake(OSCClient client, OSCMessage msg)
        {
            while (true)
            {
                yield return(new WaitForSeconds(1f));

                if (cancelRetry)
                {
                    cancelRetry = false;
                    client.Close();
                    client = null;
                    yield break;
                }

                DoError("No reply, retrying handshake");
                try {
                    client.Send(msg);
                } catch (System.Exception e) {
                    cancelRetry = true;
                    client.Close();
                    client = null;
                    DoError("Could not send to handshake server: " + e.Message);
                }
            }
        }
Ejemplo n.º 5
0
        void DoHandshake()
        {
            StopAllCoroutines();

            serverIP             = IPAddress.Parse(handshakeIP);
            GearData.handShakeIP = handshakeIP;
            try {
                //send handshake to server
                if (client != null)
                {
                    client.Close();
                    client = new OSCClient(serverIP, GearData.RECEIVE_PORT);
                }
                else
                {
                    client = new OSCClient(serverIP, GearData.RECEIVE_PORT);                     //handshake port is hardcoded
                }

                OSCMessage msg = new OSCMessage(HANDSHAKE, 0);
                client.Send(msg);

                StartCoroutine(RepeatHandshake(client, msg));
            } catch (System.Exception e) {
                cancelRetry = true;
                DoError("Could not connect to handshake server: " + e.StackTrace);
            }
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            JObject settings        = JObject.Parse(File.ReadAllText(@"..\..\settings.json"));
            int     listenPort      = settings["listenPort"].Value <int>();
            string  destination     = settings["destination"].Value <string>();
            int     destinationPort = settings["destinationPort"].Value <int>();
            bool    verbose         = settings["verbose"].Value <bool>();

            OSCServer server = new OSCServer(listenPort);
            OSCClient client = new OSCClient(destination, destinationPort);

            server.DefaultOnMessageReceived += (sender, messageArgs) =>
            {
                client.Send(messageArgs.Message);
                if (verbose)
                {
                    Console.WriteLine(messageArgs.Message.ToString());
                }
            };

            Console.WriteLine("Listening on port " + listenPort + ", sending to " + destination + " on port " + destinationPort);
            while (true)
            {
                //do nothing
            }
            ;
        }
Ejemplo n.º 7
0
    void OnPlayerPrefsUpdated(string playerPrefKey)
    {
        targetHost = PlayerPrefs_AM.GetString(playerPrefKey + "TargetIP", "127.0.0.1");
        targetPort = PlayerPrefs_AM.GetInt(playerPrefKey + "TargetPort", 9090);

        client = new OSCClient(System.Net.IPAddress.Parse(targetHost), targetPort, false);
    }
Ejemplo n.º 8
0
 public void AddReceiver(string name, string host, int port)
 {
     oscReceivers.Add(new OscReceiverInfo {
         name = name, host = host, port = port
     });
     oscReceiversDict[name] = new OSCClient(IPAddress.Parse(host), port);
 }
    // Use this for initialization
    void Awake()
    {
        client = new OSCClient(IPAddress.Parse(Host), port + droneIndex);
        Time.maximumDeltaTime = 0.1f;
        int count = UniMoveController.GetNumConnected();

        Debug.Log(count);
        // Iterate through all connections (USB and Bluetooth)
        if (moves.Count == 0)
        {
            for (int i = 0; i < count; i++)
            {
                UniMoveController move = gameObject.AddComponent <UniMoveController> ();                 // It's a MonoBehaviour, so we can't just call a constructor

                // Remember to initialize!
                if (!move.Init(i))
                {
                    Destroy(move);                       // If it failed to initialize, destroy and continue on
                    continue;
                }

                // This example program only uses Bluetooth-connected controllers
                PSMoveConnectionType conn = move.ConnectionType;
                if (conn == PSMoveConnectionType.Unknown || conn == PSMoveConnectionType.USB)
                {
                    Destroy(move);
                }
                else
                {
                    moves.Add(move);
                    move.OnControllerDisconnected += HandleControllerDisconnected;
                }
            }
        }
    }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes to OSCClient that will speak to vrc
        /// </summary>
        /// <param name="logger"></param>
        public VrcOscSender(ILog logger)
        {
            oscClient = new OSCClient(Config.OscServer, Config.OscPort);

            oscClient.OnReplyReceived += OscClient_OnReplyReceived;
            this.logger = logger;
        }
Ejemplo n.º 11
0
 void OnDestroy()
 {
     if (client != null)
     {
         client.Close();
         client = null;
     }
 }
    void Start()
    {
        _controller = new Controller();
        _oscClient  = new OSCClient(IPAddress.Loopback, 6448);
        _fingers    = new[] { thumbFinger, indexFinger, middleFinger, ringFinger, pinkyFinger };

        Debug.Log($"Device Count: {_controller.Devices.Count}");
    }
Ejemplo n.º 13
0
 public void RemoveClientAndStopDoingAnything(OSCPacket packet)
 {
     if (m_client != null)
     {
         m_client.Close();
         m_client = null;
     }
     StopDoingAnything();
 }
Ejemplo n.º 14
0
    // Use this for initialization
    void Start()
    {
        if (client == null)
        {
            client = new OSCClient(IPAddress.Parse("127.0.0.1"), 6200);
        }

        center = transform.position;
    }
Ejemplo n.º 15
0
    // Use this for initialization
    void Start()
    {
        _oscManager = GameObject.Find("OscManager").GetComponent <OscManager>();

        _sceneManager = GameObject.Find("SceneManager").GetComponent <SceneManager>();
        _lpsManager   = GameObject.Find("LpsManager").GetComponent <LpsManager>();

        _oscClient = _oscManager.CreateClient("drones");
    }
Ejemplo n.º 16
0
    // Use this for initialization
    public override void Awake()
    {
        instance = this;

        usePanel = true;
        base.Awake();

        Connect();
        client = new OSCClient(System.Net.IPAddress.Loopback, 0, false);
    }
Ejemplo n.º 17
0
    private void Test()
    {
        client = new OSCClient(IPAddress.Parse("127.0.0.1"), listenPort);
        OSCMessage m = new OSCMessage("/testMessage");

        client.Send(m);
        client.Flush();
        client.Close();
        client = null;
    }
Ejemplo n.º 18
0
    void Start()
    {
        _BodyManager = GetComponent <BodySourceManager>();

        targetHost = PlayerPrefs_AM.GetString("OSCTargetIP", "127.0.0.1");
        targetPort = PlayerPrefs_AM.GetInt("OSCTargetPort", 9090);

        client = new OSCClient(System.Net.IPAddress.Parse(targetHost), targetPort, false);

        PlayerPrefUpdateBroadcast.Instance.OnPlayerPrefsUpdated += OnPlayerPrefsUpdated;
    }
    void Awake()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
        }
        else
        {
            OSCClientIPAddress = "127.0.0.1";
        }
        InputTextPlaceHolder.text = "IP Address";
        InputText.text            = OSCClientIPAddress;

        // Create the OSCClient object to send messages
        _OSCClient = new OSCClient(IPAddress.Parse(OSCClientIPAddress), OSC_PORT);


        tileHolder = GameObject.Find("FloorPad").transform;

        tiles = new Tile[columns * rows];
        for (int i = 0; i < tiles.Length; i++)
        {
            int row       = i / rows;
            int column    = i % rows;
            int tileIndex = i + 1;

            GameObject tileGameObject = (GameObject)Instantiate(TilePrefab);
            tileGameObject.transform.position = new Vector3(rows / 2f - row - tileSize / 2f, columns / 2f - column - tileSize / 2f, 0);
            tileGameObject.transform.parent   = tileHolder;
            Tile tile = tileGameObject.GetComponent <Tile> ();
            tile.Initialize(tileIndex, this, GetTileColour(tileIndex));
            tiles [i] = tile;
        }

        // Instantiate Grid
        CreateGrid();

        // Initial settings for

        showColors  = true;
        showGrid    = false;
        showNumbers = false;
        if (Application.platform == RuntimePlatform.Android)
        {
            toggleButtons = false;
        }
        else
        {
            toggleButtons = true;
        }

        toggleButtonsToggle.isOn = toggleButtons;
        toggleColorToggle.isOn   = showColors;
        toggleGridToggle.isOn    = showGrid;
    }
Ejemplo n.º 20
0
 public void Connect(string address, int port)
 {
     try
     {
         client = new OSCClient(IPAddress.Parse(address), port);
     }
     catch (Exception e)
     {
         Debug.LogWarning(e);
         client = null;
     }
 }
Ejemplo n.º 21
0
    public void Connect()
    {
        if (client != null)
        {
            Close();
        }

        client = new OSCClient(IPAddress.Parse(ServerIP), Port);
        client.Connect();

        localhost = new OSCClient(IPAddress.Parse("127.0.0.1"), Port);
        localhost.Connect();
    }
Ejemplo n.º 22
0
        public void AddClientAndWaitForConnect(OSCPacket packet)
        {
            if (m_state != OSCInputState.WAIT_FOR_CONNECT)
            {
                return;
            }

            IPAddress clientip   = IPAddress.Parse((string)packet.Data[0]);
            int       clientport = (int)packet.Data[1];

            m_client = new OSCClient(clientip, clientport);
            WaitforConfirmConnection();
        }
Ejemplo n.º 23
0
 public bool Connect()
 {
     client = new OSCClient(IPAddress.Parse(targetAddr), targetPort);
     if (client == null)
     {
         Debug.Log("target failed connecting");
         return(false);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 24
0
        public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
        {
            if (client == null)
            {
                client = new OSCClient(IPAddress.Parse("127.0.0.1"), port);
            }

            var template = new AudioPreviewPlayable();

            template.player = player.Resolve(graph.GetResolver());
            template.client = client;
            return(ScriptPlayable <AudioPreviewPlayable> .Create(graph, template));
        }
Ejemplo n.º 25
0
    public static void CreateClient(string clientId, IPAddress destination, int port)
    {
        var client = new OSCClient(destination, port)
        {
            Name = clientId
        };

        Clients.Add(clientId, client);

        if (Instance.ShowDebug)
        {
            Debug.Log("Client " + clientId + " on " + destination + ":" + port + "created.");
        }
    }
Ejemplo n.º 26
0
    /// <summary>
    /// This function is called when the behaviour becomes disabled or inactive.
    /// </summary>
    void OnDisable()
    {
        if (reciever != null)
        {
            reciever.Close();
            reciever = null;
        }

        if (oscClient != null)
        {
            oscClient.Close();
            oscClient = null;
        }
    }
Ejemplo n.º 27
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    oscClient = null;
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }
    // Use this for initialization
    void Start()
    {
        oscManager  = GameObject.Find("OscManager").GetComponent <OscManager>();
        droneScript = gameObject.GetComponent <Drone>();

        _oscClient = oscManager.CreateClient("drones");

        // On connection : send params
        gameObject.GetComponent <Drone>().ConnectionEvent += (Drone drone) =>
        {
            foreach (PidVariable variable in variables)
            {
                SetVariable(variable.name, variable.value);
            }
        };
    }
Ejemplo n.º 29
0
    public static void SendMessage(OSCMessage m, string host, int port)
    {
        if (Instance.LogOutgoing)
        {
            string args = "";
            for (int i = 0; i < m.Data.Count; i++)
            {
                args += (i > 0 ? ", " : "") + m.Data[i].ToString();
            }

            Debug.Log("[OSCMaster | " + DateTime.Now.ToLocalTime() + "] " + m.Address + " : " + args);
        }

        var tempClient = new OSCClient(System.Net.IPAddress.Loopback, port);

        tempClient.SendTo(m, host, port);
        tempClient.Close();
    }
Ejemplo n.º 30
0
    // Use this for initialization
    void Start()
    {
        _audioSources = GameObject.FindGameObjectsWithTag("Audio");
        _speakerBase  = Speaker1.transform.position - Speaker2.transform.position;

        _playerOnBaseGameObject = new GameObject {
            name = "PlayerOnSpeakerBase"
        };
        _sourceOnBaseGameObject = new GameObject {
            name = "AudioSourceOnSpeakerBase"
        };
        _engine = this.GetComponent <Engine>();

        myClient = new OSCClient(System.Net.IPAddress.Parse("127.0.0.1"), 9000);
        var packet = new OSCMessage("/live/name/track");

        myClient.Send(packet);
    }
Ejemplo n.º 31
0
    IEnumerator StartingCoroutine()
    {
        yield return(new WaitForSeconds(0.1f));

        if (this.shouldInitialize == false) // DEBUG PURPOSE ONLY : I dont like waiting
        {
            this.system_initialized = true;
            yield break;
        }

        this._drones_osc_client      = this._oscManager.CreateClient("drones");
        this._drones_meta_osc_client = this._oscManager.CreateClient("drones_meta");
        this._oscManager.SendOscMessage(this._drones_meta_osc_client,
                                        "/server/restart",
                                        1);

        yield return(new WaitForSeconds(5));

        ConnectClientToDroneServer();

        print("Waiting for LPS and Drones managers init");
        yield return(new WaitForSeconds(0.1f));

        print("Connecting drones");
        _dronesManager.ConnectDrones();

        yield return(new WaitForSeconds(5));

        print("Sending LPS configs");
        _lpsManager.SendConfigOsc();
        yield return(new WaitForSeconds(1));

        print("Reseting kalman filters");
        _dronesManager.ResetKalmanFilters();
        print("Waiting for kalman filters to converge");
        yield return(new WaitForSeconds(1)); // It may not be enough. TODO : compute real position variance and wait for it to converge

        //this._oscManager.SendOscMessage(this._drones_osc_client,
        //    "/log/*/send_toc");
        print("SYSTEM OK");
        this.system_initialized = true;
    }
Ejemplo n.º 32
0
 void OnDisable()
 {
     oscClient = null;
 }
Ejemplo n.º 33
0
 void OnEnable()
 {
     oscClient = new OSCClient(serverHostname, serverPort);
 }
Ejemplo n.º 34
0
	static public void init()
	{
		if (isInit)
			return;

		try{

		    server = new OSCServer (5555);
		    server.PacketReceivedEvent += HandlePacketReceivedEvent;
            isInit = true;
        }
        catch(Exception e)
		{
			Debug.LogWarning("Could not create server on port 5555.");
		}

        client = new OSCClient(IPAddress.Loopback, 7776, true);
        OSCPacket.stringDecoding = System.Text.Encoding.UTF8;

		
	}
Ejemplo n.º 35
0
	// Use this for initialization
	void Start ()
	{
		client = new OSCClient (IPAddress.Parse (Host), port + droneIndex);
	}