示例#1
0
    void Start()
    {
        _mInstance = this;
        SetupRelays();
        // Initiate websocket connection here
        connection                       = gameObject.AddComponent <WSConnection>();
        connection.server                = server;
        connection.OnSocketConnected    += SocketStart;
        connection.OnNetworkTickRequest += NetworkTick;

        connection.OnSocketError += reason => Debug.LogWarning("Socket error: " + reason);

        connection.OnSocketDisconnected +=
            reason => Debug.Log("Disconnected from remote server. Reason: " + reason);

        connection.Connect();

        //connection.OnSocketConnected +=
    }
        static async Task Example(string address)
        {
            // Initilaze The SLM object
            Client slm = new Client(address);

            // Setup of the SLM, certain modes is needed to perform the LAeq measuremet
            slm.Setup_LaEQ();

            // The sequenceID of LAeq measurement
            string ID = "6";

            // Get the sequence eqaul to to the ID and read the data type
            dynamic sequence = slm.get_sequence(ID);
            string  datatype = sequence["DataType"];

            // Setup of stream with the ID and the stream name "TestStream"
            string uri = slm.setup_stream(ID, "TestStream");

            // When stream is configured a Uri to the corresponding stream is returned. Combine with the IP address of the 2245
            Uri streamUri = new Uri("ws://" + address + uri);

            // For any data to present it is required to start a recording
            slm.MeasState("start");

            // Open a websocket and connect with the obtained URI
            WSConnection wSConnection = new WSConnection();
            await wSConnection.Connect(streamUri);

            int i = 0;

            while (i <= 10)
            {
                await wSConnection.Receive_LaEQ();

                i++;
            }

            slm.MeasState("stop");
        }