Skip to main content
Participant
January 17, 2012
Question

XML via UDP

  • January 17, 2012
  • 2 replies
  • 954 views

I am trying to send an XML request via UDP to a local server using CFML.  I found the activesocket library that allows for UDP communications via ColdFusion but I'm having trouble getting the UDP object to communicate. I have used their sample Telnet application and it connects and works fine.  Is there an easier way to pass XML data via UDP from ColdFusion?   A portion of the code I'm using is below.  I am sending the data by clicking a form button and trying to pass the strXML variable to the objUdp.SendBytes function.  I have tried removing everything except the simple objUdp.open function and it still gives me the following error:

An exception occurred when accessing a Com object field.

The cause of this exception was that: AutomationException: 0x80020003 - Member not found..

<cfsavecontent variable="strXML">

<Immediate-Location-Request>

<request-id>100</request-id>

<query-info>

<ret-info ret-info-time="YES" ret-info-accuracy="YES"/>

<request-speed-hor/>

</query-info>

</Immediate-Location-Request>

</cfsavecontent>

<cfif IsDefined("URL.submitbutton")>

   <!--- creating the object --->

   <cfobject class="ActiveXperts.Udp" type="com" name="objUdp" Action="Create">

     <!--- connect to host --->

   <cfscript>

   objUdp.open(URL.host, URL.port, "False");

   objUdp.SendData "strXML"

objUdp.Close

   </cfscript>

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    January 18, 2012

    I know nothing about the library. However, I have the following 3 suggestions, from experience:

    1) Add the XML prolog directly after the cfsavecontent tag:

    <cfsavecontent variable="strXML"><?xml version="1.0" encoding="UTF-8" ?>

    <Immediate-Location-Request>

    <request-id>100</request-id>

    <query-info>

    <ret-info ret-info-time="YES" ret-info-accuracy="YES"/>

    <request-speed-hor/>

    </query-info>

    </Immediate-Location-Request>

    </cfsavecontent>

    2) Use objUdp.sendData(strXML); in place of objUdp.SendData "strXML"

    3) Use objUdp.close(); in place of objUdp.Close

    Community Expert
    January 18, 2012

    First, if you're using a modern version of CF, I'd recommend looking for a Java solution instead of using a COM object. Java can work with UDP directly - just Google "java udp" for lots of examples.

    Second, it's useful to break problems down into smaller problems - atomic ones, if you can! In this case, are you able to send any data via SendData?

    Third, wouldn't objUdp.SendData "strXML" send the literal string "strXML"?

    Dave Watts, CTO, Fig Leaf Software

    Dave Watts, Eidolon LLC