Exemplo n.º 1
0
    private IEnumerator WaitForMessage(string containingString, string errorMessage)
    {
        ramulatorWarning.SetActive(true);
        ramulatorWarningText.text = "Waiting on Ramulator";

        string receivedMessage = "";
        float  startTime       = Time.time;

        while (receivedMessage == null || !receivedMessage.Contains(containingString))
        {
            zmqSocket.TryReceiveFrameString(out receivedMessage);
            if (receivedMessage != "" && receivedMessage != null)
            {
                string messageString = receivedMessage.ToString();
                Debug.Log("received: " + messageString);
                ReportMessage(messageString, false);
            }

            //if we have exceeded the timeout time, show warning and stop trying to connect
            if (Time.time > startTime + timeoutDelay)
            {
                ramulatorWarningText.text = errorMessage;
                Debug.LogWarning("Timed out waiting for ramulator");
                yield break;
            }
            yield return(null);
        }
        ramulatorWarning.SetActive(false);
    }
Exemplo n.º 2
0
    // Client thread which does not block Update()
    void NetMQClient()
    {
        AsyncIO.ForceDotNet.Force();
        NetMQConfig.ManualTerminationTakeOver();
        NetMQConfig.ContextCreate(true);

        //string msg;
        var timeout = new System.TimeSpan(0, 0, 1); //1sec

        Debug.Log("Connect to the server.");

        pairSocket = new NetMQ.Sockets.PairSocket();
        pairSocket.Options.ReceiveHighWatermark = 0;
        //pairSocket.Connect("tcp://192.168.1.122:55555");
        pairSocket.Connect("tcp://192.168.1.111:55555");

        is_connected = true;

        while (is_connected && stop_thread_ == false)
        {
            is_connected = pairSocket.TryReceiveFrameString(timeout, out msg);
            pairSocket.TrySendFrame(timeout, final);
        }

        pairSocket.Close();
        Debug.Log("ContextTerminate.");
        NetMQConfig.ContextTerminate();
        NetMQConfig.Cleanup();
    }