C#
VB
WinRT C#
C++
Specifies which Internet Protocol Version will be supported with DICOM Communication.
[FlagsAttribute()]
public enum DicomNetIpTypeFlags
<FlagsAttribute()>
Public Enum DicomNetIpTypeFlags
[FlagsAttribute()]
public enum DicomNetIpTypeFlags
Leadtools.Dicom.DicomNetIpTypeFlags = function() { };
Leadtools.Dicom.DicomNetIpTypeFlags.prototype = {<br/>
LeadtoolsMemberMarker(replace me)
};
[FlagsAttribute()]
public enum class DicomNetIpTypeFlags
Members
Value | Member | Description |
---|---|---|
0x00000000 | None | None. |
0x00000001 | Ipv4 | Only support IPv4 addresses. |
0x00000002 | Ipv6 | Only support IPv6 addresses. |
0x00000003 | Ipv4OrIpv6 | Support both IPv4 and IPv6 addresses. |
This enumeration is used with Listen and Connect to specify the version of the Internet Protocol that will be used.
using Leadtools;
using Leadtools.Dicom;
///
[StructLayout(LayoutKind.Sequential)]
public struct MYMSG
{
public IntPtr hwnd;
public uint message;
public IntPtr wParam;
public IntPtr lParam;
public uint time;
public System.Drawing.Point p;
}
public enum MyWaitReturn
{
Complete,
Timeout,
}
class MyUtils
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool PeekMessage(out MYMSG lpMsg, IntPtr hWnd,
uint wMsgFilterMin, uint wMsgFilterMax,
uint wRemoveMsg);
[DllImport("user32.dll")]
static extern bool TranslateMessage([In] ref MYMSG lpMsg);
[DllImport("user32.dll")]
static extern IntPtr DispatchMessage([In] ref MYMSG lpmsg);
const uint PM_REMOVE = 1;
public static MyWaitReturn WaitForComplete(double mill, WaitHandle wh)
{
TimeSpan goal = new TimeSpan(DateTime.Now.AddMilliseconds(mill).Ticks);
do
{
MYMSG msg = new MYMSG();
if (PeekMessage(out msg, IntPtr.Zero, 0, 0, PM_REMOVE))
{
TranslateMessage(ref msg);
DispatchMessage(ref msg);
}
if (wh.WaitOne(new TimeSpan(0, 0, 0), false))
{
return MyWaitReturn.Complete;
}
if (goal.CompareTo(new TimeSpan(DateTime.Now.Ticks)) < 0)
{
return MyWaitReturn.Timeout;
}
} while (true);
}
}
class MyClient : DicomNet
{
DicomExceptionCode _LastError = DicomExceptionCode.Success;
AutoResetEvent waitEvent = new AutoResetEvent(false);
public MyClient()
: base(null, DicomNetSecurityeMode.None)
{
}
public DicomExceptionCode LastError
{
get
{
return _LastError;
}
}
public bool Wait()
{
_LastError = DicomExceptionCode.Success;
MyWaitReturn ret = MyUtils.WaitForComplete((5 * 60) * 1000, waitEvent);
return (ret == MyWaitReturn.Complete);
}
protected override void OnConnect(DicomExceptionCode error)
{
Debug.WriteLine("Client: Receive OnConnect");
_LastError = error;
waitEvent.Set();
}
protected override void OnReceiveReleaseResponse()
{
Debug.WriteLine("Client: Receive OnReceiveReleaseResponse");
waitEvent.Set();
}
}
class MyServerConnection : DicomNet
{
public bool Fail = false;
public MyServerConnection()
: base(null, DicomNetSecurityeMode.None)
{
}
protected override void OnReceiveReleaseRequest()
{
Debug.WriteLine("Server: Receive OnReceiveReleaseRequest");
SendReleaseResponse();
}
};
class MyServer : DicomNet
{
MyServerConnection client;
public MyServer()
: base(null, DicomNetSecurityeMode.None)
{
}
public bool Fail
{
get
{
if (client == null)
return false;
return client.Fail;
}
set
{
if (client != null)
{
client.Fail = value;
}
}
}
protected override void OnAccept(DicomExceptionCode error)
{
Debug.WriteLine("Server: Receive OnAccept");
client = new MyServerConnection();
Accept(client);
string s = string.Format("\tPeerAddress: {0}\n\tPeerPort: {1}", client.PeerAddress, client.PeerPort);
Debug.WriteLine(s);
}
}
public void DicomDataSet_ListenExample()
{
DicomEngine.Startup();
DicomNet.Startup();
using (MyServer server = new MyServer())
{
using (MyClient client = new MyClient())
{
// The * below means to listen on all local IP addresses.
// The DicomNetIpTypeFlags.Ipv4OrIpv6 means to listen on both IPv4 and IPv6 addresses
server.Listen("*", 104, 1, DicomNetIpTypeFlags.Ipv4OrIpv6); // start server
// The client is connecting to the server using an IPv6 address.
// Note that "::1" is the IPv6 loopback address
// Alternatively, you can get type ipconfig from a command box on the local computer to get the local IPv6 address.
// The following is an example of a local IPv6 address:
// "fe80::18bd:81f:6b02:759f"
client.Connect(null, 1000, "::1", 104, DicomNetIpTypeFlags.Ipv6); // connect to server
if (!client.Wait()) // wait for connection to finish
{
Debug.Fail("Connection timed out");
}
Debug.Assert(client.LastError == DicomExceptionCode.Success, "Connection failed");
Debug.Assert(client.IsConnected(), "Client not connected");
client.SendReleaseRequest();
if (!client.Wait()) // wait for connection to finish
{
Debug.Fail("Timed Out");
}
// Close the connections
client.CloseForced(true);
}
server.CloseForced(true);
}
DicomEngine.Shutdown();
DicomNet.Shutdown();
}
Imports Leadtools
Imports Leadtools.Dicom
'''
<StructLayout(LayoutKind.Sequential)>
Public Structure MYMSG
Public hwnd As IntPtr
Public message As UInteger
Public wParam As IntPtr
Public lParam As IntPtr
Public time As UInteger
Public p As System.Drawing.Point
End Structure
Public Enum MyWaitReturn
Complete
Timeout
End Enum
Friend Class MyUtils
<DllImport("user32.dll")>
Shared Function PeekMessage(<System.Runtime.InteropServices.Out()> ByRef lpMsg As MYMSG, ByVal hWnd As IntPtr, ByVal wMsgFilterMin As UInteger,
ByVal wMsgFilterMax As UInteger, ByVal wRemoveMsg As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("user32.dll")>
Shared Function TranslateMessage(ByRef lpMsg As MYMSG) As Boolean
End Function
<DllImport("user32.dll")>
Shared Function DispatchMessage(ByRef lpmsg As MYMSG) As IntPtr
End Function
Private Const PM_REMOVE As UInteger = 1
Public Shared Function WaitForComplete(ByVal mill As Double, ByVal wh As WaitHandle) As MyWaitReturn
Dim goal As New TimeSpan(DateTime.Now.AddMilliseconds(mill).Ticks)
Do
Dim msg As New MYMSG()
If PeekMessage(msg, IntPtr.Zero, 0, 0, PM_REMOVE) Then
TranslateMessage(msg)
DispatchMessage(msg)
End If
If wh.WaitOne(New TimeSpan(0, 0, 0), False) Then
Return MyWaitReturn.Complete
End If
If goal.CompareTo(New TimeSpan(DateTime.Now.Ticks)) < 0 Then
Return MyWaitReturn.Timeout
End If
Loop While True
End Function
End Class
Friend Class MyClient
Inherits DicomNet
Private _LastError As DicomExceptionCode = DicomExceptionCode.Success
Private waitEvent As New AutoResetEvent(False)
Public Sub New()
MyBase.New(Nothing, DicomNetSecurityeMode.None)
End Sub
Public ReadOnly Property LastError() As DicomExceptionCode
Get
Return _LastError
End Get
End Property
Public Function Wait() As Boolean
_LastError = DicomExceptionCode.Success
Dim ret As MyWaitReturn = MyUtils.WaitForComplete((5 * 60) * 1000, waitEvent)
Return (ret = MyWaitReturn.Complete)
End Function
Protected Overrides Sub OnConnect(ByVal [error] As DicomExceptionCode)
Debug.WriteLine("Client: Receive OnConnect")
_LastError = [error]
waitEvent.Set()
End Sub
Protected Overrides Sub OnReceiveReleaseResponse()
Debug.WriteLine("Client: Receive OnReceiveReleaseResponse")
waitEvent.Set()
End Sub
End Class
Friend Class MyServerConnection
Inherits DicomNet
Public Fail As Boolean = False
Public Sub New()
MyBase.New(Nothing, DicomNetSecurityeMode.None)
End Sub
Protected Overrides Sub OnReceiveReleaseRequest()
Debug.WriteLine("Server: Receive OnReceiveReleaseRequest")
SendReleaseResponse()
End Sub
End Class
Friend Class MyServer
Inherits DicomNet
Private client As MyServerConnection
Public Sub New()
MyBase.New(Nothing, DicomNetSecurityeMode.None)
End Sub
Public Property Fail() As Boolean
Get
If client Is Nothing Then
Return False
End If
Return client.Fail
End Get
Set(ByVal value As Boolean)
If client IsNot Nothing Then
client.Fail = value
End If
End Set
End Property
Protected Overrides Sub OnAccept(ByVal [error] As DicomExceptionCode)
Debug.WriteLine("Server: Receive OnAccept")
client = New MyServerConnection()
Accept(client)
Dim s As String = String.Format(Constants.vbTab & "PeerAddress: {0}" & Constants.vbLf + Constants.vbTab & "PeerPort: {1}",
client.PeerAddress, client.PeerPort)
Debug.WriteLine(s)
End Sub
End Class
Public Sub DicomDataSet_ListenExample()
DicomEngine.Startup()
DicomNet.Startup()
Using server As New MyServer()
Using client As New MyClient()
' The * below means to listen on all local IP addresses.
' The DicomNetIpTypeFlags.Ipv4OrIpv6 means to listen on both IPv4 and IPv6 addresses
server.Listen("*", 104, 1, DicomNetIpTypeFlags.Ipv4OrIpv6) ' start server
' The client is connecting to the server using an IPv6 address.
' Note that "::1" is the IPv6 loopback address
' Alternatively, you can get type ipconfig from a command box on the local computer to get the local IPv6 address.
' The following is an example of a local IPv6 address:
' "fe80::18bd:81f:6b02:759f"
client.Connect(Nothing, 1000, "::1", 104, DicomNetIpTypeFlags.Ipv6) ' connect to server
If (Not client.Wait()) Then ' wait for connection to finish
Debug.Fail("Connection timed out")
End If
Debug.Assert(client.LastError = DicomExceptionCode.Success, "Connection failed")
Debug.Assert(client.IsConnected(), "Client not connected")
client.SendReleaseRequest()
If (Not client.Wait()) Then ' wait for connection to finish
Debug.Fail("Timed Out")
End If
' Close the connections
client.CloseForced(True)
End Using
server.CloseForced(True)
End Using
DicomEngine.Shutdown()
DicomNet.Shutdown()
End Sub
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET