Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (first)
        {
            if (client.isConnected)
            {
                StartCoroutine(SendMessageDelayed("" + number, waitTime));

                first = false;
            }
        }
        else
        {
            if (client.infoReceived.Count > 0)
            {
                COMData data = client.infoReceived.Dequeue();

                if (data.type == COMData.TYPE.TEXT)
                {
                    COMData_text text = (COMData_text)data;

                    ProcessMessage(text);
                }
            }
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (server.infoReceived.Count > 0)
        {
            KeyValuePair <int, COMData> data = server.infoReceived.Dequeue();

            if (data.Value.type == COMData.TYPE.TEXT)
            {
                COMData_text text = (COMData_text)data.Value;

                ProcessMessage(text, data.Key);
            }
        }
    }
Esempio n. 3
0
    private void Client_OnReceive(object sender, SocketArgs e)
    {
        //Debug.Log("Client_OnReceive" + e != null ? ": " + e.message : "");
        Debug.Log("Client_OnReceive: ");

        COMData data = client.infoReceived.Dequeue();

        if (data.type == COMData.TYPE.TEXT)
        {
            COMData_text text = (COMData_text)data;

            ProcessMessage(text);
            //Log.Debug("Message Received: " + text.GetText());
        }
    }
Esempio n. 4
0
    void ProcessMessage(COMData_text msg)
    {
        string txt = msg.GetText();

        //ANALYSE MESSAGE
        textUI.text = txt;

        Log.Debug(txt);
        int count = 0;

        try {
            count = System.Convert.ToInt32(txt);
        }
        catch (System.Exception) {
            Debug.Log("ERROR ON MESSAGE - " + txt);
        }

        StartCoroutine(SendMessageDelayed("" + (count + 1), waitTime));
    }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        if (server.infoReceived.Count > 0)
        {
            KeyValuePair <int, COMData> data = server.infoReceived.Dequeue();

            if (data.Value.type == COMData.TYPE.TEXT)
            {
                COMData_text text = (COMData_text)data.Value;

                Log.Debug(data.Key + "|Message Received: " + text.GetText());
            }
            else
            if (data.Value.type == COMData.TYPE.IMAGE)
            {
                COMData_image image = (COMData_image)data.Value;

                if (imageReceived == null)
                {
                    imageReceived = new Texture2D(image.imageWidth, image.imageHeight);
                }
                else
                {
                    if (image.imageWidth != imageReceived.width || image.imageHeight != imageReceived.height)
                    {
                        imageReceived = new Texture2D(image.imageWidth, image.imageHeight);
                    }
                }
                imageReceived.LoadImage(image.data);

                Log.Debug("Image Received: " + imageReceived.width + " x " + imageReceived.height);

                GameObject.Find("RawImage").GetComponent <RawImage>().texture = imageReceived;

                //server.BroadcastMessage("READY");
            }
            else
            if (data.Value.type == COMData.TYPE.AUDIO)
            {
            }
        }
    }
Esempio n. 6
0
    //int framesSkiped = 30;
    //int counter = 0;
    //void FixedUpdate()
    //{
    //	if (sendImages)
    //	{
    //		counter++;
    //		if (counter == framesSkiped)
    //		{
    //			if (webCam == null)
    //				webCam = GameObject.Find("Main Camera").GetComponent<WebCam>().cam;

    //			if (textureTemp == null)
    //				textureTemp = new Texture2D(webCam.width, webCam.height);

    //			textureTemp.SetPixels32(webCam.GetPixels32());

    //			imageConverted = textureTemp.EncodeToPNG();

    //			client.SendInfo_image(imageConverted, textureTemp.width, textureTemp.height);

    //			counter = 0;
    //		}
    //	}
    //}
    // Update is called once per frame
    void Update()
    {
        if (client.infoReceived.Count > 0)
        {
            COMData data = client.infoReceived.Dequeue();

            if (data.type == COMData.TYPE.TEXT)
            {
                COMData_text text = (COMData_text)data;

                Log.Debug("Message Received: " + text.GetText());

                if (sendImages)
                {
                    if (text.GetText() == "READY")
                    {
                        SendImage();
                    }
                }
            }
            else
            if (data.type == COMData.TYPE.IMAGE)
            {
                COMData_image image = (COMData_image)data;

                Texture2D texture = new Texture2D(image.imageWidth, image.imageHeight);
                texture.LoadImage(image.data);
                texture.Apply();

                Log.Debug("Image Received: " + texture.width + " x " + texture.height);

                GameObject.Find("RawImage").GetComponent <RawImage>().texture = texture;
            }
            else
            if (data.type == COMData.TYPE.AUDIO)
            {
            }
        }
    }
Esempio n. 7
0
    bool SendText(COMData_text text)
    {
        string header =
            COMData.macroInit +
                text.type +
                COMData.macroSeparator +
                text.data.Length +
                COMData.macroEnd;

        Log.AddToDebug(header);
        socket.Send(System.Text.Encoding.UTF8.GetBytes (header));
        int bytesSent = socket.Send(text.data);

        return bytesSent == text.data.Length;
    }
Esempio n. 8
0
    void ReceiveMessage(int messageSize)
    {
        COMData_text message = new COMData_text();
        message.data = new byte[messageSize];

        int sizeReceived = socket.Receive(message.data);

        if(messageSize == sizeReceived){
            infoReceived.Enqueue(message);

            Log.AddToDebug("Message Received: " + message.data.Length);
        }
    }
    void ReceiveMessage(int messageSize)
    {
        COMData_text message = new COMData_text();
        message.data = new byte[messageSize];

        int sizeReceived = socket.Receive(message.data);

        Log.AddToDebug("Message Received: " + messageSize + " - " + sizeReceived);

        if(messageSize == sizeReceived){
            server.infoReceived.Enqueue(new KeyValuePair<int, COMData>(id, message));

            Log.AddToDebug("Message Received: " + message.data.Length);
        }
    }