Skip to content

Commit

Permalink
enable local IP setting iKadmium#17
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffputz committed Jul 10, 2023
1 parent b64f5f2 commit 509301f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Kadmium-sACN/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace Kadmium_sACN
{
public static class Constants
{
public const int Port = 5568;
public const int RemotePort = 5568;
public const int LocalPort = 5569;
public const int MaxPacketLength = 1444;
public const int Universe_MinValue = 1;
public const int Universe_MaxValue = 63999;
Expand Down
2 changes: 1 addition & 1 deletion Kadmium-sACN/SacnReceiver/SacnReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected SacnReceiver(ISacnMulticastAddressProvider ipv4Provider, ISacnMulticas

public void Listen(IPAddress address)
{
var endpoint = new IPEndPoint(address, Constants.Port);
var endpoint = new IPEndPoint(address, Constants.RemotePort);

Pipe pipe = new Pipe();
Socket = new Socket(endpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
Expand Down
12 changes: 10 additions & 2 deletions Kadmium-sACN/SacnSender/SacnSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ public class SacnSender : IDisposable
private ISacnMulticastAddressProvider Ipv6MulticastAddressProvider { get; }
private Socket Ipv4Socket { get; } = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
private Socket Ipv6Socket { get; } = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);

private IPAddress _ip;

public SacnSender() : this(new SacnMulticastAddressProviderIPV4(), new SacnMulticastAddressProviderIPV6())
{ }

public SacnSender(IPAddress localAddress) : this(new SacnMulticastAddressProviderIPV4(), new SacnMulticastAddressProviderIPV6())
{ }

protected SacnSender(ISacnMulticastAddressProvider ipv4AddressProvider, ISacnMulticastAddressProvider ipv6AddressProvider)
{
Ipv4MulticastAddressProvider = ipv4AddressProvider;
Expand All @@ -28,13 +33,16 @@ protected SacnSender(ISacnMulticastAddressProvider ipv4AddressProvider, ISacnMul

protected async Task SendInternal(IPAddress address, SacnPacket packet)
{
var endpoint = new IPEndPoint(address, Constants.Port);
var endpoint = new IPEndPoint(address, Constants.RemotePort);
using (var owner = MemoryPool<byte>.Shared.Rent(packet.Length))
{
var bytes = owner.Memory.Slice(0, packet.Length);
packet.Write(bytes.Span);
var socket = address.AddressFamily == AddressFamily.InterNetworkV6 ? Ipv6Socket : Ipv4Socket;


if (_ip != null)
socket.Bind(new IPEndPoint(_ip, Constants.LocalPort));

var args = new SocketAsyncEventArgs
{
SocketFlags = SocketFlags.None,
Expand Down

0 comments on commit 509301f

Please sign in to comment.