Exemple #1
0
        void Tick()
        {
            //if (client.Available == 0) return;
            if (udpclient.Available == 0)
            {
                return;
            }

            // Get received data
            IPEndPoint sender = new IPEndPoint(0, 0);

            //Byte[] receivedBytes = udpclient.EndReceive(ar, ref sender);
            Byte[] receivedBytes = udpclient.Receive(ref sender);
            string strValue      = Encoding.ASCII.GetString(receivedBytes);
            //Debug.Log("strValue: " + strValue);

            CommsMessage message = JsonUtility.FromJson <CommsMessage>(strValue);

            foreach (var callback in callbacks)
            {
                if (callback.Key == message.id)
                {
                    callback.Value(message.payload);
                }
            }
        }
Exemple #2
0
        public void JsToUnity(string strValue)
        {
            CommsMessage message = JsonUtility.FromJson <CommsMessage>(strValue);

            foreach (var callback in callbacks)
            {
                if (callback.Key == message.id)
                {
                    callback.Value(message.payload);
                }
            }
        }