static NetMQTransport()
 {
     if (!(Type.GetType("Mono.Runtime") is null))
     {
         ForceDotNet.Force();
     }
 }
    protected override void Run()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet
        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");

            while (Running)
            {
                if (waitingForRequest != null)
                {
                    string message;
                    bool   gotMessage = client.TryReceiveFrameString(out message);
                    if (gotMessage)
                    {
                        waitingForRequest.image.RecieveResults(waitingForRequest.request, message);
                        waitingForRequest = null;
                    }
                }
                else if (requests.Count > 0)
                {
                    var request = requests.Dequeue();
                    client.SendFrame(request.request.HamiltonianString());
                    waitingForRequest = request;
                }
            }
        }

        NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet
    }
    protected /*override*/ void Run2()
    {
        ForceDotNet.Force();
        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");

            while (running)
            {
                //Debug.Log("Sending Hello");
                //client.SendFrame("subject: " + subject.x + "; " + subject.y);
                client.SendFrame(JsonUtility.ToJson(subject));
                Debug.Log("Sent " + JsonUtility.ToJson(subject));

                string message    = null;
                bool   gotMessage = false;
                while (running)
                {
                    gotMessage = client.TryReceiveFrameString(out message);
                    if (gotMessage)
                    {
                        break;
                    }
                }

                if (gotMessage)
                {
                    Debug.Log("Received " + message);
                    UnityMainThreadDispatcher.Instance().Enqueue(HandleMessage(message));
                }
            }
        }

        NetMQConfig.Cleanup();
    }
    public void sendRequest(byte[] imageAI)
    {
        ForceDotNet.Force();
        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");
            Debug.Log("Sending Picture");
            client.SendFrame(imageAI);
            string message    = null;
            bool   gotMessage = false;
            while (true)
            {
                gotMessage = client.TryReceiveFrameString(out message);
                if (gotMessage)
                {
                    break;
                }
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    break;
                }
            }

            if (gotMessage)
            {
                Debug.Log("Received " + message);
            }
        }

        NetMQConfig.Cleanup();
    }
Exemple #5
0
    protected override void Run()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet

        Debug.Log("Subscriber started");
        using (var subSocket = new SubscriberSocket())
        {
            //subSocket.Options.ReceiveHighWatermark = 1000;
            subSocket.Connect("tcp://127.0.0.1:5555");
            subSocket.Subscribe("22");
            Console.WriteLine("Subscriber socket connecting...");
            while (Running)
            {
                string messageTopicReceived = subSocket.ReceiveFrameString();
                string messageReceived      = subSocket.ReceiveFrameString();
                //Debug.Log(messageReceived);
                carFrontX = Convert.ToSingle(messageReceived.Split(' ')[1]) / 100;
                carFrontZ = Convert.ToSingle(messageReceived.Split(' ')[2]) / 100;
                carBackX  = Convert.ToSingle(messageReceived.Split(' ')[3]) / 100;
                carBackZ  = Convert.ToSingle(messageReceived.Split(' ')[4]) / 100;

                //Debug.Log(carFrontX.ToString() + ":" + carFrontZ.ToString() + " " +carBackX.ToString() + ":" + carBackZ.ToString());
            }
        }
        NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet
    }
        public void Awake()
        {
            DontDestroyOnLoad(this);

            ForceDotNet.Force();
            NetMQConfig.Linger = TimeSpan.Zero;

            Debugger.WriteLine(LogLevel.Info, $"Starting up Maid Fiddler {VERSION}");

            MFService service = new MFService();

            Debugger.WriteLine(LogLevel.Info, $"Creating a ZeroService at tcp://localhost:{PORT}");

            zeroServer = new Server(new SimpleWrapperService <MFService>(service));

            zeroServer.Error += (sender, args) =>
            {
                Debugger.WriteLine(LogLevel.Error, $"ZeroService error: {args.Info.ToString()}");
            };

            Debugger.WriteLine(LogLevel.Info, "Starting server!");

            zeroServer.Bind($"tcp://localhost:{PORT}");

            Debugger.WriteLine(LogLevel.Info, "Started server!");
        }
    public string sendRequestPredict(byte[] imageAI)
    {
        ForceDotNet.Force();
        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");
            Debug.Log("Sending Picture");
            client.SendFrame(imageAI);
            string message    = null;
            bool   gotMessage = false;
            while (true)
            {
                gotMessage = client.TryReceiveFrameString(out message);
                if (gotMessage)
                {
                    break;
                }
            }

            if (gotMessage)
            {
                Debug.Log("Received " + message);
                //return float.Parse(message, CultureInfo.InvariantCulture.NumberFormat);
                return(message);
            }
            //return 0f;
            return(null);
        }
    }
Exemple #8
0
 // Start is called before the first frame update
 void Start()
 {
     ForceDotNet.Force();
     client = new RequestSocket();
     client.Connect("tcp://localhost:5555");
     Debug.Log("connected");
 }
Exemple #9
0
    protected override void Run()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet
        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");

            while (Running)
            {
                Debug.Log("Request");
                if (isReady)
                {
                    client.SendFrame(makeAngleJSON());
                    string message    = null;
                    bool   gotMessage = false;
                    while (Running)
                    {
                        gotMessage = client.TryReceiveFrameString(out message); // this returns true if it's successful
                        if (gotMessage)
                        {
                            break;
                        }
                    }
                    if (gotMessage)
                    {
                        Debug.Log("Received " + message);
                        isReady = false;
                    }
                }
            }
        }

        NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet
    }
    protected override void Run()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet
        using (RequestSocket client = new RequestSocket())
        {
            //client.Connect("tcp://localhost:5555");
            client.Connect("tcp://192.168.1.191:5566");
            while (Running)
            {
                //Debug.Log("Sending Hello");
                client.SendFrame("Hello");
                string message    = null;
                bool   gotMessage = false;
                while (Running)
                {
                    gotMessage = client.TryReceiveFrameString(out message); // this returns true if it's successful
                    if (gotMessage)
                    {
                        break;
                    }
                }

                if (gotMessage)
                {
                    //Debug.Log("Received " + message);
                    callback(message);
                }
            }
        }

        NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet
    }
Exemple #11
0
    //public HelloRequester(TrafficLightAI trafficLightAI)
    //{
    //    this.trafficLightAI = trafficLightAI;
    //}
    /// <summary>
    ///     Request Hello message to server and receive message back. Do it 10 times.
    ///     Stop requesting when Running=false.
    /// </summary>
    protected override void Run()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet
        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");

            for (int i = 0; Running; i++)
            {
                Debug.Log("Sending Hello");
                client.SendFrame("Hello");
                // ReceiveFrameString() blocks the thread until you receive the string, but TryReceiveFrameString()
                // do not block the thread, you can try commenting one and see what the other does, try to reason why
                // unity freezes when you use ReceiveFrameString() and play and stop the scene without running the server
//                string message = client.ReceiveFrameString();
//                Debug.Log("Received: " + message);
                gotMessage = false;
                while (Running)
                {
                    gotMessage = client.TryReceiveFrameString(out message); // this returns true if it's successful
                    if (gotMessage)
                    {
                        break;
                    }
                }
                var p = 0;
                if (gotMessage)
                {
                    //trafficLightAI = GameObject.FindGameObjectWithTag("TrafficLightHolder").GetComponent<TrafficLightAI>();
                    //trafficLightAI.getMessage(message);
                    //Debug.Log("Received int " + int.TryParse(message, out p));

                    Debug.Log("Received string " + message);

                    if (message.Length >= 6)
                    {
                        int[] a = new int[] { (int)char.GetNumericValue(message[3]), (int)char.GetNumericValue(message[5]) };

                        CreateCars.getTheMessage(a);
                    }

                    /*
                     * if (ctr == 0)
                     * {
                     *  permanentMessage1 = message;
                     * }
                     *
                     * else if (ctr == 2)
                     * {
                     *  permanentMessage2 = message;
                     *  ctr = 0;
                     * }
                     * ctr++;
                     */
                }
            }
        }

        NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet
    }
Exemple #12
0
        //public int timeLimit = 120;
        //Add option to modify this in AppOptions

        protected override void Run()
        {
            ForceDotNet.Force();
            //socket = new RequestSocket();
            //socket.Connect("tcp://localhost:5555");
            Debug.Log("Communication started");

            if (option == CommunicatorOption.RECEIVE_DATA)
            {
                socket = new RequestSocket();
                socket.Connect(address);
                //Debug.Log("Communication started");

                dataList = new List <float[]>();

                ReceiveOnePointData();
            }
            else if (option == CommunicatorOption.SEND_DATA)
            {
                socket = new ResponseSocket();
                socket.Bind(address);
                //Debug.Log("Communication started");

                CreateByteData();
                SendOnePointData();
            }
            //byte_dataList
        }
Exemple #13
0
    /// <summary>
    ///     Request Hello message to server and receive message back. Do it 10 times.
    ///     Stop requesting when Running=false.
    /// </summary>
    protected override void Run()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet
        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");

            while (true)
            {
                byte[] frameBuffer;
                if (playerController.CanGetFrame())
                {
                    frameBuffer = playerController.getFrame();
                    client.SendFrame(frameBuffer);
                    string message    = null;
                    bool   gotMessage = false;
                    while (true)
                    {
                        gotMessage = client.TryReceiveFrameString(out message); // this returns true if it's successful
                        if (gotMessage)
                        {
                            break;
                        }
                    }

                    if (gotMessage)
                    {
                        Debug.Log("Received " + message);
                    }
                }
            }
            NetMQConfig.Cleanup();
        }
    }
Exemple #14
0
    protected override void Run()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet
        using (RequestSocket client = new RequestSocket())
        {
            client.Connect(serverIP);

            status = "Not Connect";
            for (; Running;)
            {
                status = "Sending...";
                client.SendFrame("START SEND FILE:" + fileName);
                ReceiveMessage(client);
                var bytes = System.IO.File.ReadAllBytes(sendFilePath + fileName + ".txt");
                client.SendFrame(bytes);
                ReceiveMessage(client);

                client.SendFrame("COMPLETE:" + fileName);
                ReceiveMessage(client);
                if (status.Contains("ERROR"))
                {
                    break;
                }
                status = "COMPLETE: " + fileName;
                break;
            }
        }
        NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet
    }
Exemple #15
0
        public MessageClient(string ip_address = "127.0.0.1",
                             int port          = 6969,
                             bool use_inter_process_communication = false,
                             bool debug = false,
                             Double wait_time_seconds = 2)
        {
            this._wait_time_seconds = wait_time_seconds;
            this.Debugging          = debug;
            this._ip_address        = ip_address;
            this._port = port;
            this._use_inter_process_communication = use_inter_process_communication;

      #if NEODROID_DEBUG
            if (this.Debugging)
            {
                Debug.Log($"Starting a message server at address:port {ip_address}:{port}");
            }
      #endif

            if (!this._use_inter_process_communication)
            {
                ForceDotNet.Force();
            }

            this._socket = new ResponseSocket();
        }
Exemple #16
0
    public override void Run()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use

        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");

            string signal     = "None";
            bool   gotMessage = false;

            //Debug.Log("----Sending Signal----");
            client.SendFrame(message);

            while (Running)
            {
                gotMessage = client.TryReceiveFrameString(out signal);                 // this returns true if it's successful
                if (gotMessage)
                {
                    break;
                }
            }

            if (gotMessage)
            {
                //Debug.Log("----Recived Signal: " + signal);
                EmotionInput.activeEmotion = signal;
                Running = false;
            }
        }
        NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use
    }
    protected override void Run()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet
        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");

            while ((message != "--end--") && Running)
            {
                // ReceiveFrameString() blocks the thread until you receive the string, but TryReceiveFrameString()
                // do not block the thread, you can try commenting one and see what the other does, try to reason why
                // unity freezes when you use ReceiveFrameString() and play and stop the scene without running the server

                bool gotMessage = false;

                if (hasData != inHasData)
                {
                    hasData = inHasData;
                }
                if (lastHasData != hasData)
                {
                    if (!hasData)
                    {
                        Debug.Log("Sending Start");
                        client.SendFrame("--start--");
                        message = null;
                    }
                    lastHasData = hasData;
                }
                while (Running && !hasData)
                {
                    gotMessage = client.TryReceiveFrameString(out msg); // this returns true if it's successful
                    if (gotMessage)
                    {
                        break;
                    }
                }
                if (gotMessage && (msg == "--end--"))
                {
                    Debug.Log("Got END");
                    break;
                }
                if (gotMessage && (msg != "--eof--"))
                {
                    message += msg;
                    client.SendFrame("--cont--");
                }
                if (gotMessage && (msg == "--eof--"))
                {
                    Debug.Log("Got EOF");
                    hasData   = true;
                    inHasData = true;
                }
            }
            Debug.Log("Data receiving ended");
        }

        NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet
    }
    protected override void Run()
    {
        while (Running && !killProcess)
        {
            connectionStatus = false;
            attemptReconnect = false;
            ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet

            using (RequestSocket client = new RequestSocket())
            {
                client.Connect("tcp://localhost:5555");
                //client.Connect("tcp://10.9.72.2:5555"); // for connecting to roborio

                while (Running && !killProcess)
                {
                    client.SendFrame(jsonify());

                    string message    = null;
                    bool   gotMessage = false;
                    receiveStartTime = unityPacket.heartbeat;

                    while (Running && !killProcess)
                    {
                        gotMessage = client.TryReceiveFrameString(out message); // this returns true if it's successful

                        deadTime = unityPacket.heartbeat - receiveStartTime;

                        // Debug.Log("Time until attemp reconnect: " + deadTime);

                        if (giveUpTime < deadTime)
                        {
                            attemptReconnect = true;
                            break;
                        }

                        if (gotMessage)
                        {
                            break;
                        }
                    }

                    if (attemptReconnect)
                    {
                        break;
                    }

                    if (gotMessage)
                    {
                        //Debug.Log("Received " + message);
                        decodeMessage(message);
                    }

                    connectionStatus = true;
                }
            }

            NetMQConfig.Cleanup();
        }
    }
        public EventManager()
        {
            ForceDotNet.Force();
            workers             = new HashSet <BackgroundWorker>();
            publisherSocket     = new PublisherSocket(transportMethod + "eventsystem");
            subscriberDelegates = new Dictionary <string, HashSet <Action <string, object[]> > >();

            Debug.Log("EventManager created");
        }
 /// <summary>
 ///     Request Hello message to server and receive message back. Do it 10 times.
 ///     Stop requesting when Running=false.
 /// </summary>
 protected override void Run()
 {
     ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet
     using (RequestSocket client = new RequestSocket())
     {
         client.Connect("tcp://localhost:5555");
     }
     NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet
 }
Exemple #21
0
    // Start is called before the first frame update
    public void start(int port)
    {
        ServerEndpoint = $"tcp://localhost:{port}";

        ForceDotNet.Force();
        Debug.Log($"C: Connecting to server...{ServerEndpoint}");

        client = new RequestSocket();
        client.Connect(ServerEndpoint);
    }
Exemple #22
0
 public AsyncSocketTests(bool forceDotNet)
 {
     if (forceDotNet)
     {
         ForceDotNet.Force();
     }
     else
     {
         ForceDotNet.Unforce();
     }
 }
Exemple #23
0
        protected override void Run()
        {
            ForceDotNet.Force();

            dataList = new List <float[]>();

            socket = new RequestSocket();
            socket.Connect("tcp://localhost:5555");
            Debug.Log("Communication started");

            ReceiveOnePointData();
        }
Exemple #24
0
 protected override void Run()
 {
     ForceDotNet.Force();
     using var socket = new PushSocket();
     socket.Connect("tcp://localhost:5556");
     while (Running)
     {
         if (fromEventLoop.TryDequeue(out byte[] img))
         {
             socket.TrySendFrame(img);
         }
     }
 }
Exemple #25
0
    void Awake()
    {
        ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet

        // Create Response(Server) socket
        responseSocket = new ResponseSocket("@tcp://localhost:8555");

        // Create a server thread for receiving messages from Python code
        ThreadStart serverThreadStart = new ThreadStart(GetRequest);

        serverThread = new Thread(serverThreadStart);
        serverThread.IsBackground = true;
        serverThread.Start();
    }
Exemple #26
0
    void Start()
    {
        Process foo = new Process();

        foo.StartInfo.FileName    = "E:\\PythonUnityCommunication\\Assets\\Scripts\\CommunicatorPython.py";
        foo.StartInfo.Arguments   = "";
        foo.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
        foo.Start();
        ForceDotNet.Force();
        client = new RequestSocket();
        client.Connect("tcp://localhost:55");
        client.SendFrame("Hello");
        count = 0;
    }
Exemple #27
0
    protected override void Run()
    {
        ForceDotNet.Force();                  // this line is needed to prevent unity freeze after one use, not sure why yet

        using (server = new ResponseSocket()) // check if its response or request ?
        {
            server.Bind("tcp://*:1234");      //SEND

            using (client = new RequestSocket())
            {
                client.Connect("tcp://localhost:2222"); // RECIEVE


                // for (int i = 0; i < 2 && Running; i++)
                while (Running)
                {
                    // TO BE ABLE TO SEND USING SERVER SOCKET:
                    string DummyServerReceive = server.ReceiveFrameString();
                    //Debug.Log("MY DUMMY SERVER REC: " + DummyServerReceive);
                    //SENDING TO SERVER :  //SEND A VARIABLE BOOLEAN HERE
                    server.SendFrame(Mode + "," + Yindex + "," + Xindex + "," + Resign + "," + Pass + "," + HumanColor);
                    //Pass = "******";
                    //Resign = "-1";
                    //Debug.Log("SERVER IS DONE ");

                    // DUMMY SEND OF CLIENT TO RECEIVE
                    client.SendFrame("HELLOOOOOOO");

                    while (Running)
                    {
                        message = client.ReceiveFrameString(); // this returns true if it's successful

                        //Debug.Log("MESSAGE IS :" + this.message);

                        break;
                    }
                }

                client.Disconnect("tcp://localhost:2222");
                client.Close();
                client.Dispose();
            }
            server.Disconnect("tcp://*:1234");
            server.Close();
            server.Dispose();
        }

        NetMQConfig.Cleanup();
    }
Exemple #28
0
    protected override void Run()
    {
        ForceDotNet.Force();
        finalPath = new int[1000];

        // Create a new socket that binds to the port number for the first seeker character, as defined in Python.
        using (RequestSocket client = new RequestSocket())
        {
            // Port number for the first character defined in Python.
            client.Connect("tcp://localhost:5555");
            while (Running)
            {
                if (Send)
                {
                    // Here, the message string that is defined in 'HelloClient' is sent over the socket.
                    client.SendFrame(messageToSend);

                    string message    = null;
                    bool   gotMessage = false;

                    while (Running)
                    {
                        gotMessage = client.TryReceiveFrameString(out message); // this returns true if it's successful
                        if (gotMessage)
                        {
                            break;
                        }
                    }
                    if (gotMessage)
                    {
                        // Here, the string received from Python (the final path) is split to remove unnecessary characters.
                        // Furthermore, it is put into a static array, so the coordinates can be easily accessed in Pathfinding.cs

                        string newMessage       = message.Replace("(", "");
                        string newNewMessage    = newMessage.Replace(")", "");
                        string newNewNewMessage = newNewMessage.Replace(",", "");



                        string[] finalStringPath = newNewNewMessage.Split();
                        finalPath = finalStringPath.Select(s => int.Parse(s)).ToArray();
                    }
                }
            }
        }

        NetMQConfig.Cleanup();
    }
Exemple #29
0
 public MessageServer(
     string ip_address = "127.0.0.1",
     int port          = 5555,
     bool use_inter_process_communication = false,
     bool debug = false)
 {
     this.Debugging   = debug;
     this._ip_address = ip_address;
     this._port       = port;
     this._use_inter_process_communication = use_inter_process_communication;
     if (!this._use_inter_process_communication)
     {
         ForceDotNet.Force();
     }
     this._socket = new ResponseSocket();
 }
    ///     Stop requesting when Running=false.
    protected override void Run()
    {
        ForceDotNet.Force();

        using (RequestSocket client = new RequestSocket())
        {
            client.Connect("tcp://localhost:5555");

            while (Running)
            {
                if (Send)
                {
                    //string message = client.ReceiveFrameString();
                    client.SendFrame(bytes);
                    string message    = null;
                    bool   gotMessage = false;

                    while (Running)
                    {
                        gotMessage = client.TryReceiveFrameString(out message); // this returns true if it's successful
                        if (gotMessage)
                        {
                            break;
                        }
                    }
                    if (gotMessage)
                    {
                        //   Debug.Log("Received " + message);

                        if (message == "Failed to make plan")
                        {
                        }
                        else
                        {
                            if (msgEvent != null)
                            {
                                msgEvent.Invoke(message);
                            }
                        }
                    }
                    Send = false;
                }
            }
        }

        NetMQConfig.Cleanup();
    }