CoAP.Net icon indicating copy to clipboard operation
CoAP.Net copied to clipboard

Support IPv4 and IPv6 at same socket

Open Lybecker opened this issue 7 years ago • 5 comments

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/

Lybecker avatar Aug 24 '18 09:08 Lybecker

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

NZSmartie avatar Aug 24 '18 09:08 NZSmartie

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 [email protected] 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 .

Lybecker avatar Aug 24 '18 09:08 Lybecker

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

NZSmartie avatar Aug 24 '18 09:08 NZSmartie

@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.<SendAsync>d__37.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.<SendAsyncInternal>d__41.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.<SendAsync>d__40.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.TaskAwaiter1.GetResult() at CoAPNet.CoapClient.<SendAsync>d__37.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.TaskAwaiter1.GetResult() at CoAPDevices.Program.<Main>d__0.MoveNext() in C:\Dev\CoAP.Net.git\samples\SimpleClient\Program.cs:line 44 Press <Enter> 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?

andygikling avatar May 10 '19 19:05 andygikling

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

Lybecker avatar May 15 '19 23:05 Lybecker