NZSmartie / CoAP.Net

Constrained Applciaiton Protocol (CoAP) [RFC7252] for .Net Standard
https://nzsmartie.co.nz/CoAP.Net/
Apache License 2.0
34 stars 11 forks source link

Support IPv4 and IPv6 at same socket #14

Open Lybecker opened 6 years ago

Lybecker commented 6 years ago

Current implementation of CoapUdpEndPoint does not support IPv4 and IPv6 at the same time.

Actually the default constructor CoapUdpEndPoint is hardcoded to IPv4 with the IPAddress.Any (Any means IPv4 and IPv6Any means IPv6) The samples was ailing due to this, so I set out to figure out why and lean myself. So I wrote a blog post: http://www.lybecker.com/blog/2018/08/23/supporting-ipv4-and-ipv6-dual-mode-network-with-one-socket/

NZSmartie commented 6 years ago

Ah, good catch. I haven't been able to test with IPv6 yet, i'll get onto that soon.

Lybecker commented 6 years ago

I have a pull request coming up... Just cannot figure out how to create unit tests

On Fri, Aug 24, 2018 at 11:50 AM, Roman Vaughan notifications@github.com wrote:

Ah, good catch. I haven't been able to test with IPv6 yet, i'll get onto that soon.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/NZSmartie/CoAP.Net/issues/14#issuecomment-415711016, or mute the thread https://github.com/notifications/unsubscribe-auth/ADvRrX7S2cXrfG_Pj1RnOHT_KsuPpo5aks5uT8xjgaJpZM4WLD9g .

NZSmartie commented 6 years ago

If you submit what you have so far as a PR, i can investigate the tests

andygikling commented 5 years ago

@Lybecker, @NZSmartie

I'm testing the out of the box client and server with your merged changes under VS2019. I'm getting a curious exception related to the section of code that was changed above (I think).

System.Net.Sockets.SocketException: 'An invalid argument was supplied'

This happens immediately when the client tries to send the hello put to the server. The full stack trace I get in my client window is this:

Exception caught: System.Net.Sockets.SocketException (0x80004005): An invalid argument was supplied at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName) at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.Bind(EndPoint localEP) at CoAPNet.Udp.CoapUdpEndPoint.BindAsync() in C:\Dev\CoAP.Net.git\src\CoAPNet.Udp\CoapUdpEndPoint.cs:line 100 at CoAPNet.Udp.CoapUdpEndPoint.d37.MoveNext() in C:\Dev\CoAP.Net.git\src\CoAPNet.Udp\CoapUdpEndPoint.cs:line 171 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CoAPNet.CoapClient.d41.MoveNext() in C:\Dev\CoAP.Net.git\src\CoAPNet\CoapClient.cs:line 502 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CoAPNet.CoapClient.d40.MoveNext() in C:\Dev\CoAP.Net.git\src\CoAPNet\CoapClient.cs:line 464 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at CoAPNet.CoapClient.d37.MoveNext() in C:\Dev\CoAP.Net.git\src\CoAPNet\CoapClient.cs:line 406 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at CoAPDevices.Program.

d__0.MoveNext() in C:\Dev\CoAP.Net.git\samples\SimpleClient\Program.cs:line 44 Press to exit

Do you have any insights for this? I haven't looked into it yet unfortunately. I'm just shopping for .net coap libraries. I'm a little surprised the demo client/server didn't work out of the box.

Thoughts?

Lybecker commented 5 years ago

It is due to the client tries to bind twice to the same endpoint in two different threads. I don't know why