Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTTServer in UWP #46

Closed
haeberle opened this issue Sep 26, 2017 · 1 comment
Closed

MQTTServer in UWP #46

haeberle opened this issue Sep 26, 2017 · 1 comment

Comments

@haeberle
Copy link

Dear’s

First of all, thank a lot for the great solution.

I did some test by using the MQTTserver in a UWP app and identified an issue. I used the example code from the Readme and set the Port to 1883 in the DefaultEndpointOptions.
The Server runs into a Nullpointer Exception, because the ReceiveStream in the MqttTcpChannel is not initialized. I see that the initialization is done in the ConnectAsync method, but it looks the method is used in MQQTClient context but not if the Channel is used in Server context.

My fix in MqttTcpChannel (MQTTnet.UniversalWindows), please validate ;-)
…..

public MqttTcpChannel(StreamSocket socket)
{
	_socket = socket ?? throw new ArgumentNullException(nameof(socket));
	CreateStreams(socket);
}
private void CreateStreams(StreamSocket socket)
{
	SendStream = socket.OutputStream.AsStreamForWrite();
	ReceiveStream = socket.InputStream.AsStreamForRead();
	RawReceiveStream = ReceiveStream;
}
public async Task ConnectAsync(MqttClientOptions options)
{
	if (options == null) throw new ArgumentNullException(nameof(options));
	if (_socket == null)
	{
		_socket = new StreamSocket();
	}
	if (!options.TlsOptions.UseTls)
	{
		await _socket.ConnectAsync(new HostName(options.Server), options.GetPort().ToString());
	}
	else
	{
		_socket.Control.ClientCertificate = LoadCertificate(options);

		if (!options.TlsOptions.CheckCertificateRevocation)
		{
			_socket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.IncompleteChain);
			_socket.Control.IgnorableServerCertificateErrors.Add(ChainValidationResult.RevocationInformationMissing);
		}

		await _socket.ConnectAsync(new HostName(options.Server), options.GetPort().ToString(), SocketProtectionLevel.Tls12);
	}

	CreateStreams(_socket);
}

Cheers

@chkr1011
Copy link
Collaborator

Hi,
thank you for your bug report. You are right this is a bug and I fixed it in the way you proposed.
A new version will be released soon.

Best regards
Christian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants