/// <summary> /// Update client Ip address /// </summary> protected virtual void UpdateIpAddress() { // create socket for updating IP address using (this.updateIpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { this.updateIpSocket.Connect(this.updateIpEndPoint); // prepare buffers for send and receive this.sendBuffer = Encoding.UTF8.GetBytes(this.updateIpCmd.ToString()); this.receiveBuffer = new byte[RECEIVE_BUFFER_SIZE]; int byteRead = 0; // SSL configured if (this.ddnsConfig.SSL) { // create SSL stream using (Microsoft.SPOT.Net.Security.SslStream sslStream = new Microsoft.SPOT.Net.Security.SslStream(this.updateIpSocket)) { // SSL handshake authentication sslStream.AuthenticateAsClient(this.updateIpHost, Microsoft.SPOT.Net.Security.SslProtocols.TLSv1); // send message sslStream.Write(this.sendBuffer, 0, this.sendBuffer.Length); // cycle for reading from socket int offset = 0; int read = 0; do { read = sslStream.Read(this.receiveBuffer, offset, RECEIVE_BUFFER_SIZE - offset); offset += read; } while (read != 0); byteRead = offset; } } else { // send message and read response this.updateIpSocket.Send(this.sendBuffer); byteRead = this.updateIpSocket.Receive(this.receiveBuffer); } if (byteRead > 0) { this.response = this.DecodeUpdateIpResponse(new String(Encoding.UTF8.GetChars(this.receiveBuffer))); // raise IP address updated event this.OnIpAddressUpdated(new IpAddressUpdatedEventArgs { IpAddress = this.ipAddress, Response = this.response }); } } }