private void ConnectToServerCallback(SecureTCPClient myTCPClient) { try { if (myTCPClient.ClientStatus == SocketStatus.SOCKET_STATUS_CONNECTED) { MqttMsgConnect connect = MsgBuilder.BuildConnect(this.ClientId, MqttSettings.Instance.Username, MqttSettings.Instance.Password, this.WillRetain, this.WillQosLevel, this.WillFlag, this.WillTopic, this.WillMessage, this.CleanSession, this.KeepAlivePeriod, ProtocolVersion); Send(connect); //TODO: timer for connack tcpClient.ReceiveData(); MqttMsgBase packet = PacketDecoder.DecodeControlPacket(tcpClient.IncomingDataBuffer); if (packet.Type == MqttMsgBase.MQTT_MSG_CONNACK_TYPE) { RouteControlPacketToMethodHandler(packet); } else { throw new MqttConnectionException("MQTTCLIENT - ConnectToServerCallback - " + PayloadMapper.ClientType + " , Expected CONNACK , received " + packet, new ArgumentException()); } } } catch (MqttClientException e) { CrestronLogger.WriteToLog("MQTTCLIENT - ConnectToServerCallback - Error occured : " + e.ErrorCode, 7); CrestronLogger.WriteToLog("MQTTCLIENT - ConnectToServerCallback - Error occured : " + e.StackTrace, 7); } catch (Exception e) { CrestronLogger.WriteToLog("MQTTCLIENT - ConnectToServerCallback - Error occured : " + e.Message, 7); CrestronLogger.WriteToLog("MQTTCLIENT - ConnectToServerCallback - Error occured : " + e.StackTrace, 7); //Disconnect from server , signal error at module lvl; } }
internal int ClientReceiveData() { if (EnableSSL) { return(SSLClient.ReceiveData()); } else { return(NoSSLClient.ReceiveData()); } }