Specifying outgoing IP when making a DICOM connection
It is possible to choose which outgoing interface to use when making an outgoing DICOM association using code such as below:
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
var localEP = new IPEndPoint(IPAddress.Parse("outgoingIP"), 0); // 0 means any available port
socket.Bind(localEP);
var remoteEP = new IPEndPoint(IPAddress.Parse("remoteIP"), remotePort);
socket.Connect(remoteEP);
NetworkStream ns = new NetworkStream(socket, true);
DicomAssociation cn = new DicomAssociation();
cn.RequestedContexts.Add("1.2.840.10008.1.1");
cn.Open(socket, ns, "callingAET", "calledAET");
int status = cn.Echo();
cn.Close();
}