Ali cloud Things .NET Core Client | CZGL.AliIoTClient:. 2 IoT client

Documents directory:


 

1) The client connector

CZGL.AliIoTClient, there are two things aliyun connected to the server:

public CZGL.AliIoTClient.ConnectCode ConnectIoT(string[] SubTopic, [byte[] QOS = null], [ushort keepAlivePeriod = 60]) 
public System.Threading.Tasks.Task<CZGL.AliIoTClient.ConnectCode> ConnectIoTAsync(string[] topics, [byte[] QOS = null], [ushort keepAlivePeriod = 60]) 

Parameters and return value:

parameter name Types of Explanation
SubTopic string[] To subscribe to the Topic list, only to subscribe to this Topic, will receive the server push this Topic
QOS byte[] Each Topic can configure a QOS, if empty, will be set up for each Topic QOS = 0x00, note QOS 0,1,2 only three types so using the most appropriate byte
keepAlivePeriod ushort Alive monitoring period, MQTT communication requirements of each interval of time, client feedback, to prove the survival of the client, over this period, the server assumes that the client has been dropped.
return value ConnectCode It is connected to the return status code, enumerated types, because even if a key error, network disconnection caused by a connection failure will not trigger an exception, it returns a status code

Topic Each attribute has a QOS, the QOS SubTopic length and should be consistent, but also the position corresponding to the index.

QOS meanings:

  • QOS = 0, at most once
  • QOS = 1, at least once
  • QOS = 2, only once

ConnectCode:

When a client tries to establish a connection with the server, may succeed or fail, then returns specific information about the connection status, ConnectCode enumeration as follows:

Enumeration name Enumeration values Explanation
conn_accepted 0x00 connection succeeded
conn_refused_prot_vers 0x01 Protocol Version
conn_refused_ident_rejected 0x02 Certification was denied
conn_refused_server_unavailable x03 Server 403/404, etc.
conn_refused_username_password 0x04 Account password error
conn_refused_not_authorized 0x05 Not authorized
unknown_error 0x06 Other unknown error

Example:

            var code = client.ConnectIoT(topics, null, 60);
            Console.WriteLine("连接状态:" + code); 

2) Disconnect

public bool ConnectIoTClose() 

Disconnected, completely release AliIoTClientJson objects, not just offline To reconnect, re-new object;

Example:

 client.ConnectIoT(topics,null,60);

3) Check the status

See if the client remains connected to the server:

public bool isConnected { get; }

Example:

Console.WriteLine("是否与服务器连接保持连接:" + client.isConnected);

Guess you like

Origin www.cnblogs.com/whuanle/p/10994673.html