Community discussions

 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1264
Joined: Sun Sep 18, 2011 7:00 pm

getting information from port - remote access

Wed Oct 03, 2018 1:25 pm

Hello -
strange problem :
when I have a someone connected I get this replay :
"!re=.id=*1=port=serial0=channel=0=allowed-addresses=0.0.0.0/0=tcp-port=8271=protocol=raw=log-file==remote-address=10.0.0.60:49972=active=true=disabled=false"
which is good because I can know if someone connected

but when now one is connected I only get part of the replay
"!re=.id=*1=port=serial0=channel=0=allowed-addresses=0.0.0.0/0=tcp-port=8271=protocol=raw=log-file==disabled=false"
which is a problem....
so how can I know if someone is connected or not? shuld I take the length of the answer? ot the number of the "=" ?
or there is another better solution ?

* the code is in C# ....
what whould you suggest ?

Thanks ,
 
nescafe2002
Long time Member
Long time Member
Posts: 622
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: getting information from port - remote access

Wed Oct 03, 2018 1:47 pm

You could check for the appearance of substring "=active=true":

var connected = response.Contains("=active=true");

I suggest to use tik4net higher lever api:

void Main()
{
  using (var conn = ConnectionFactory.OpenConnection(TikConnectionType.Api, "192.168.88.1", 8728, "admin", "password"))
  {
    var port = conn.LoadAll<RemoteAccess>().First();
    var connected = port.Active;
  }
}

[TikEntity("/port/remote-access", IncludeDetails = true)]
public class RemoteAccess
{
  [TikProperty(".id")]
  public string Id { get; private set; }

  [TikProperty("active")]
  public bool Active { get; private set; }

  [TikProperty("port")]
  public string Port { get; private set; }

  [TikProperty("channel")]
  public int Channel { get; private set; }

  [TikProperty("allowed-addresses")]
  public string AllowedAddresses { get; private set; }

  [TikProperty("local-address")]
  public string LocalAddress { get; private set; }

  [TikProperty("tcp-port")]
  public int TcpPort { get; private set; }

  [TikProperty("protocol")]
  public string Protocol { get; private set; }

  [TikProperty("log-file")]
  public string LogFile { get; private set; }

  [TikProperty("remote-address")]
  public string RemoteAddress { get; private set; }
}
 
David1234
Forum Guru
Forum Guru
Topic Author
Posts: 1264
Joined: Sun Sep 18, 2011 7:00 pm

Re: getting information from port - remote access

Wed Oct 03, 2018 3:15 pm

I didn't about using "Contains"...

which is the same as see the size of the answer

I'm using this - so Thanks ,!

Who is online

Users browsing this forum: No registered users and 9 guests