NetReceiveAssociateRequest Example for Visual Basic

Private Sub LEADDICOMNet1_NetReceiveAssociateRequest (ByVal hNet As Long, ByVal hPDU As Long)

    Dim x As Long
    Dim nId As Integer
    Dim nResult As Integer
    Dim szAbstract As String
    Dim szTransfer As String
    
    'we have received an AssociateRequest
    List2.AddItem "Associate Request was received"
    
    'check the version, if not 1, reject it
    If (LEADDICOMNet1.GetVersion (hPDU) <> 1) Then
        LEADDICOMNet1.SendAssociateReject hNet, PDU_REJECT_RESULT_PERMANENT, _
                                                 PDU_REJECT_SOURCE_USER, _
                                                 PDU_REJECT_REASON_UNKNOWN
    Else
        'send associate accept class back
        LEADDICOMNet1.CreateAssociate False
        LEADDICOMNet1.ResetAssociate LEADDICOMNet1.hPDU, False
        'copy all presentation objects from received hPDU
        'also, reply that we only support the first Transfer Syntax from the received hPDU
        For x = 0 To LEADDICOMNet1.GetPresentationCount (hPDU) - 1
            nId = LEADDICOMNet1.GetPresentationID (hPDU, x)
            szTransfer = LEADDICOMNet1.GetTransferSyntax(hPDU, nId, 0)
            nResult = PDU_ACCEPT_RESULT_SUCCESS
            szAbstract = LEADDICOMNet1.GetPresentationAbstract (hPDU, nId)
            LEADDICOMNet1.AddPresentation LEADDICOMNet1.hPDU, nId, nResult, szAbstract
            LEADDICOMNet1.AddTransferSyntax LEADDICOMNet1.hPDU, nId, szTransfer
        Next
        LEADDICOMNet1.SendAssociateAccept hNet
        LEADDICOMNet1.FreeAssociate LEADDICOMNet1.hPDU
    End If

End Sub