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

Added support for dual mode socket (IPv4 and IPv6) at the same time. #15

Merged
merged 2 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion samples/SimpleServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void Main(string[] args)

try
{
myServer.BindTo(new CoapUdpEndPoint(IPAddress.Any, Coap.Port) { JoinMulticast = true });
myServer.BindTo(new CoapUdpEndPoint(Coap.Port) { JoinMulticast = true });

myServer.StartAsync(myHandler, CancellationToken.None).GetAwaiter().GetResult();

Expand Down Expand Up @@ -61,6 +61,8 @@ public HelloResource(string uri) : base(uri)

public override CoapMessage Get(CoapMessage request)
{
Console.WriteLine($"Got request: {request}");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, but I added it to make it visible when the server received a request


return new CoapMessage
{
Code = CoapMessageCode.Content,
Expand Down
6 changes: 4 additions & 2 deletions src/CoAPNet.Udp/CoapUdpEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public CoapUdpEndPoint(UdpClient udpClient, ILogger<CoapUdpEndPoint> logger = nu
}

public CoapUdpEndPoint(int port = 0, ILogger<CoapUdpEndPoint> logger = null)
: this(new IPEndPoint(IPAddress.Any, port), logger)
: this(new IPEndPoint(IPAddress.IPv6Any, port), logger)
{ }

public CoapUdpEndPoint(IPAddress address, int port = 0, ILogger<CoapUdpEndPoint> logger = null)
Expand Down Expand Up @@ -94,7 +94,9 @@ public Task BindAsync()
throw new InvalidOperationException("Can not bind to remote endpoint");


Client = new UdpClient(_endpoint) { EnableBroadcast = true };
Client = new UdpClient(AddressFamily.InterNetworkV6) { EnableBroadcast = true };
Client.Client.DualMode = true;
Client.Client.Bind(_endpoint);

if (JoinMulticast)
{
Expand Down