I managed to have a get and set with unity through telnet but how can I use the subscribe? I would like to use it for a simple on-off button where I don't have to check for changes in value constantly.
the only details I get from the wiki are:
unlike the 'get'/set commands, the 'subscribe' command needs its argument to be an absolute path from the root, for example:
subscribe /sim/time/real/seconds
For each changed property, the notification response will be in the form of: /some/property=value (terminator)
this is my code for the getter:
- Code: Select all
public async Task<string> AsyncGet (string command)
{
this.callType = "get";
try
{
if (this.netStream != null && this.netStream.CanWrite)
{
this.strmWriter.WriteLine($"get {command}");
this.strmWriter.Flush();
while(!this.netStream.DataAvailable)
await Task.Delay(1);
//readline return result <fg command>='<value>'
return this.SubStrResult(this.strmReader.ReadLine(), '\'', '\'');
}
}
catch (Exception ex)
{
Debug.LogError($"{this.LogHeader} unable to get. {ex.Message}");
}
return default;
}
what it does is after it sends the command with StreamWriter, it just waits for the stream to update and return what is in the StreamReader.
and for example, when I press a key on the keyboard I can get a return just with
- Code: Select all
string visable = await this.AsyncGet("sim/yokes-visible");
with the code above, I don't see how I can use subscribe like an event when the return is a string.
I'm a baby in the concept of interfacing and network, so will be great if detailed explanations can be given in c#/unity.
thanks in advance