static NetMQTransport() { if (!(Type.GetType("Mono.Runtime") is null)) { ForceDotNet.Force(); } }
//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 }
//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 }
/// <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(); } }
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 }
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(); } }
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 }
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 }
// 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); }
public AsyncSocketTests(bool forceDotNet) { if (forceDotNet) { ForceDotNet.Force(); } else { ForceDotNet.Unforce(); } }
protected override void Run() { ForceDotNet.Force(); dataList = new List <float[]>(); socket = new RequestSocket(); socket.Connect("tcp://localhost:5555"); Debug.Log("Communication started"); ReceiveOnePointData(); }
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); } } }
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; }
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(); }
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(); }
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(); }
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(); }
/// Stop requesting when Running=false. protected override void Run() { ForceDotNet.Force(); finalPath1 = new int[1000]; using (RequestSocket client = new RequestSocket()) { client.Connect("tcp://localhost:5550"); while (Running) { if (Send) { //string message = client.ReceiveFrameString(); client.SendFrame(messageToSend1); 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); string newMessage = message.Replace("(", ""); string newNewMessage = newMessage.Replace(")", ""); string newNewNewMessage = newNewMessage.Replace(",", ""); string[] finalStringPath = newNewNewMessage.Split(); finalPath1 = finalStringPath.Select(s => int.Parse(s)).ToArray(); } } } } NetMQConfig.Cleanup(); }
// Overide the run thread 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()) { string addr = "tcp://localhost:" + port; client.Connect(addr); while (Running) { if (newDataFlag) { Debug.Log("ZMQRequester-> Data Sent through ZMQ."); client.SendFrame(sendData); newDataFlag = false; byte[] response = null; double[] parsedResponse = null; bool gotResponse = false; while (Running) { gotResponse = client.TryReceiveFrameBytes(out response); // this returns true if it's successful if (gotResponse) { break; } } if (gotResponse) { parsedResponse = parseReceivedData(response); string responseStr = null; foreach (double element in parsedResponse) { responseStr += element.ToString() + ","; } Debug.Log("ZMQRequester<- Received: " + responseStr); } } } } NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet }
protected override void Run() { ForceDotNet.Force(); using (RequestSocket client = new RequestSocket()) { //Port number in the TCP connection client.Connect("tcp://localhost:5555"); while (Running) { if (Send) { //The image file path is sent over the socket client.SendFrame(imageMessage); 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); //Remove unnecessary characters from the received classification result //Then split the result where there is a space, and store it in a string array messageFromServer = message.Replace(":", "").Replace("(", "").Replace(")", "").Split(' '); //Add the string array elements to a string list whoIsThatPokemon.AddRange(messageFromServer); } } } } NetMQConfig.Cleanup(); }
/// <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 (ResponseSocket server = new ResponseSocket()) { server.Bind("tcp://*:5555"); //missatge buit per defecte buit, ocupat i resultat 0 FeedbackInfo fbInfo = new FeedbackInfo(); string str = JsonUtility.ToJson(fbInfo); msg_back = str; string message = null; bool gotMessage = false; // mentre estem escoltant while (Running) { gotMessage = server.TryReceiveFrameString(out message); // this returns true if it's successful if (gotMessage) { //si estem processant un missatge no desem com a pendent if (processingMessage == true) { Debug.Log("msg_back " + msg_back); server.SendFrame(msg_back); //si estem lliures el desem } else { pending_message = message; Debug.Log("msg_back " + msg_back); server.SendFrame(msg_back); } } } } NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet }
/// <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"); if (k % 2 == 0) { client.SendFrame("OFF"); } else { client.SendFrame("ON"); } // 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); 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); } } } NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet }
/// 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) { Message jsonMessage = JsonUtility.FromJson <Message>(message); Globals.setMoveDir(jsonMessage.move); if (jsonMessage.done) { Globals.done = jsonMessage.done; } Globals.setGoalCount(jsonMessage.goalCount); } } } } NetMQConfig.Cleanup(); }
/// Stop requesting when Running=false. protected override void Run() { ForceDotNet.Force(); using (RequestSocket client = new RequestSocket()) { client.Connect("tcp://localhost:5550"); while (Running) { if (Send) { //string message = client.ReceiveFrameString(); client.SendFrame(messageToSend); 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); //GameObject.Find("PokeDex").GetComponent<pokeBoy>().Status = GameObject.Find("PokeDex").GetComponent<pokeBoy>().Status + "\n" + message; // finalPath = finalStringPath.Select(s => int.Parse(s)).ToArray(); // wird wird empfangen } } } } NetMQConfig.Cleanup(); }
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(stepNumber.ToString()); 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); errorFeedback = message.Split(' '); Debug.Log("Color is " + errorFeedback[0]); Debug.Log("Shape is " + errorFeedback[1]); Debug.Log("Position is " + errorFeedback[2]); Debug.Log("Height is " + errorFeedback[3]); } } } } NetMQConfig.Cleanup(); }
protected override void Run() { ForceDotNet.Force(); using (RequestSocket client = new RequestSocket()) { //Port number for the first client in the TCP connection client.Connect("tcp://localhost:5555"); while (Running) { if (Send) { //The start and end positions and the grid are 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) { //Remove unnecessary characters from the path received from the server var numbers = message.Replace("(", "").Replace(",", "").Replace(")", ""); //Split the string path whenever a space is encountered, //then convert it into integers and save them in an integer array algorithmPath = numbers.Split(' ').Select(int.Parse).ToArray(); } } } } NetMQConfig.Cleanup(); }
// Overide the run thread protected override void Run() { ForceDotNet.Force(); // this line is needed to prevent unity freeze after one use, not sure why yet using (PushSocket client = new PushSocket()) { string addr = "tcp://localhost:" + port; client.Connect(addr); while (Running) { if (newDataFlag) { //Debug.Log("ZMQPusher-> Data Sent through ZMQ."); client.SendFrame(sendData); newDataFlag = 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://192.168.43.129:5555"); //for (int i = 0; i < 10 && Running; i++) //{ Debug.Log("Sending Hello"); //Debug.Log(img32); //client.SendFrame(Color32ArrayToByteArray(img32)); //client.SendFrame("frick"); client.SendFrame(HelloClient.photoBytes); // 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); message = ""; 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); msg = message; } //} } NetMQConfig.Cleanup(); // this line is needed to prevent unity freeze after one use, not sure why yet }