- Home /
Which ways are available for a Unity program to communicate with other programs?
I have node.js on my computer. I was trying to communicate with Unity using Socket.io. This however seems to be very difficult because of loads of errors and bad examples in projects on github.com
I know you can request websites with the WWW class, but this is too slow if you want to update a position of an object many times a second (please correct me if I am wrong!).
So I was wandering in which ways (www, [ws://], [ipc://]) can Unity communicate with the computer or other programs outside of it's own environment?
And maybe which type of communication is already made for Node.js? (since that's the program I am using to control communications from other ip's)
Hi because the answers above are from 2014 , I wonder if this answer is still relevant and updated thanks
Answer by fafase · Apr 02, 2014 at 06:53 PM
www class should be fast enough, we are currently working on a project where a server update position of up to 8 objects (only 8 for now 20 coming up) and it works fine with www request. There would be a latency if you were contacting a remote server but when on the same computer the request is almost instant.
If you do not have a server set up you can probably use localhost and use the request. The other solution is just to use a classic text read/write and parser since you know where the json file is stored.
Thank you for you answer! It is on the same computer indeed. How then would Unity know something changed in the text file? Constantly on every Update() read the file and check changes? Or clear the file if something has been processed (this would then defeat the purpose of being able to push data right?) ?
Well considering the other application is constantly writing over the existing file, you can have a coroutine to check for the file and see for modifications:
void Start(){
StartCoroutine(CheckFile());
}
IEnumerator CheckFile()
{
float freq = 0.5f;
float timer = 0; // This is to lower frequency of check
while(true){
WWW www = new WWW(url);
// Check for www.error
// Parse and check for info
while(timer < freq){ // 2Hz frequency
timer += Time.deltaTime;
yield return null;
}
timer = 0f;
yield return null;
}
}
Thank you, I will try this code! If it works you'll get the thumbs up! =)
Hey it's working quite fast, however adding more values I am afraid it might become slow but for now it's most certainly a good solution! Thanks!
Your answer
Follow this Question
Related Questions
Problems with UDP data sending 1 Answer
Is there a more flexible method of sending data over network than RPC? 1 Answer
LAN NetworkTransport communication issue 1 Answer
UNet does not call OnServerReady on second connect from same machine 0 Answers
Unity Mirror Networking - can't create a server on a build game, IL2CPP Mistake 0 Answers