Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default cfscript

    since i cannot find the cf and java integration thread, gues i will post this
    here: i wrote a cfm with cfscript that utilizes java which connects to a
    socket on another server. everything is working, but i would like to add a
    timeout. we are still on cf5 so i cannot use the try/catch in cfscript. if i
    would like to init setsotimeout, any ideas on how or where it would be placed?
    i have an example of my code posted thanx for any help!!

    <cfscript>
    // create the Java object Socket to connect with TCP
    socket = CreateObject("java", "java.net.Socket");
    // javacast the IP address to string for Socket
    SevIP = javacast("string", "10.10.10.10");
    // javacast the Port to an Int for Socket
    SevPort = javacast("int", 4000);
    // call the Socket object (cf utilizes init())
    socket.init(SevIP, SevPort);
    // get the IP address from the socket connection (this will verify that you
    are connedted
    SevGetIP = socket.toString();
    // get the port in which you are connected to
    SevGetPort = socket.getPort();
    // close the socket (if you do not do this, it will lock
    the socket and port so that no other user may
    // connect)
    socket.close();
    </cfscript>

    bikerboy Guest

  2. Similar Questions and Discussions

    1. substring method in cfscript?
      Forgive me in advance for asking this very elementary question, but I am writing a function enclosed within <cfscript> tags, and I need to get the...
    2. CFSCRIPT Special Characters
      An external application posts a $ (%24) at the beginning of each querysting. I am able to reference the querystring through normal cf tags, but not...
    3. <cfscript> autocaps problem </cfscript> - betcha can't fix this!
      First, I'll tell you up front that I am clueless when it comes to cfscript. So I apologize if this question is off topic. I have a nice little...
    4. cfscript and variables
      I'm using cfscript against a COM object. In VB the paramater is passed like: Set oSegment = oTransactionset.CreateDataSegment('BEG')...
    5. vbscript to cfscript
      I'm trying to assign a value to an object. I have an example in asp that works and I'm trying to get it to work in cfscript. Here's the vbscript: ...
  3. #2

    Default Re: cfscript

    well you could wrap the whole cfscript in a cftry/cfcatch block. as for the timeout, can't you do a socket.setSoTimeout(100); ?
    PaulH Guest

  4. #3

    Default Re: cfscript

    i tried that, but nada. it just goes to the same exception error. i need it to
    close the socket, and send a nice message to the user that the server is
    currently unavailable (or something to that fact). thanx sean

    bikerboy Guest

  5. #4

    Default Re: cfscript

    tried what? something like this?

    <cftry>
    <cfscript>
    // create the Java object Socket to connect with TCP
    socket = CreateObject("java", "java.net.Socket");
    // javacast the IP address to string for Socket
    SevIP = javacast("string", "10.10.10.10");
    // javacast the Port to an Int for Socket
    SevPort = javacast("int", 4000);
    // call the Socket object (cf utilizes init())
    socket.init(SevIP, SevPort);
    // set timeout
    socket.setSoTimeout(100);
    // get the IP address from the socket connection (this will verify that you
    are connedted
    SevGetIP = socket.toString();
    // get the port in which you are connected to
    SevGetPort = socket.getPort();
    </cfscript>
    <cfcatch type="java.net.SocketException"> <!--- or maybe Any --->
    <!--- close the socket (if you do not do this, it will lock the socket and
    port so that no other user may connect) --->
    <cfset socket.close()>
    </cfcatch>
    </cftry>

    PaulH Guest

  6. #5

    Default Re: cfscript

    i had just worked on the cftry-catch and that did the trick. i was thinking that it needed to be internal with the cfscript (like with the newer versions of cf).

    golden!
    thanx
    bikerboy Guest

  7. #6

    Default Re: cfscript

    um, don't forget logic to close the socket if everything went ok & the connection is no longer needed.

    PaulH Guest

  8. #7

    Default Re: cfscript

    yep, just for the heck of it, i attached my test code. thanx again!

    <!--- set the test mask to send to the coder --->
    <cfset Variables_CC_Mask_Parsed = "006 OCT 11 04 06 09:34">
    <cftry>
    <cfscript>
    // create the Java object Socket to connect with TCP
    socket = CreateObject("java", "java.net.Socket");
    // javacast the IP address to string for Socket
    SevIP = javacast("string", "10.10.10.10");
    // javacast the Port to an Int for Socket
    SevPort = javacast("int", 4000);
    // call the Socket object (cf utilizes init())
    socket.init(SevIP, SevPort);
    // set the timeout to occur
    socket.setSoTimeout(100);
    // get the IP address from the socket connection (this will verify that you
    are connedted
    SevGetIP = socket.toString();
    // get the port in which you are connected to
    SevGetPort = socket.getPort();
    // set the string which will be sent to the CaseCoder
    CoderMenu = "MMS232";
    // set the case code to send to the coder
    CodeString = "#Variables_CC_Mask_Parsed#";
    // create the Java object PrintWriter which will send the data to the
    CaseCoder (set as DataOut)
    DataOut = CreateObject("java", "java.io.PrintWriter");
    // call the PrintWriter object (getOutPutStream())
    DataOut.init(socket.getOutPutStream());
    // send the ASCII ^T <SYN> to initialize the casecoder to accept the new
    string (^T is for predefined
    // strings that are setup in the casecoder, ^V would initialize a string that
    you created)
    DataOut.write(chr(20));
    // send the ^T
    DataOut.Flush();
    // create the Java object Thread which create a pause in executing the code.
    this will delay the
    // packets being sent to the casecoder, if they are sent without a delay
    inbetween, then the casecoder
    // will not beable to respond
    WriteDelay = CreateObject("java", "java.lang.Thread");
    // call the Thread object
    WriteDelay.init();
    // delay transmition for 100ml
    WriteDelay.sleep(100);
    // prepare the casecode you wish to start printing (sending the MMS232)
    DataOut.write('#CoderMenu#');
    // send the casecode you wish to start printing
    DataOut.Flush();
    // delay transmition for 100ml
    WriteDelay.sleep(100);
    // send the ASCII ^M to <CR> to upload what you have in the
    buffer(CaseString1) to start Printing
    DataOut.write(chr(13));
    // send the ^M
    DataOut.Flush();
    // delay transmition for 100ml
    WriteDelay.sleep(100);
    // send the ASCII ^T <SYN> to initialize the casecoder to accept the new
    string (^T is for predefined
    // strings that are setup in the casecoder, ^V would initialize a string that
    you created)
    DataOut.write(chr(22));
    // send the ^V
    DataOut.Flush();
    // delay transmition for 100ml
    WriteDelay.sleep(100);
    // prepare the casecode you wish to start printing
    DataOut.write('#CodeString#');
    // send the casecode you wish to start printing
    DataOut.Flush();
    // delay transmition for 100ml
    WriteDelay.sleep(100);
    // send the ASCII ^M to <CR> to upload what you have in the
    buffer(CaseString1) to start Printing
    DataOut.write(chr(13));
    // send the ^M
    DataOut.Flush();
    // delay transmition for 100ml
    WriteDelay.sleep(100);
    // send the ASCII ^A to <SOH> to release the buffer and start Printing
    DataOut.write(chr(1));
    // send the ^A
    DataOut.Flush();
    // Print out some nice message to test that the procedure has transacted
    //WriteOutPut("Greetings from: #SevGetIP#<br>");
    //WriteOutPut("Your are connected to Port: #SevGetPort#<br>");
    // close the PrintWriter object
    DataOut.close();
    // close the socket (if you do not do this, it will lock the socket and port
    so that no other user may
    // connect)
    socket.close();
    // let them know that it had closed
    WriteOutPut("The connection has been closed.");
    </cfscript>
    <cfcatch type="any">
    <cfset socket.close()>
    <cfset CCMsg = "An error occurred with sending data to the CaseCoder. Please
    contact your local IT dept.">
    <cfabort>
    </cfcatch>
    </cftry>
    <cfif not isDefined('CCMsg')>
    <cfset CCMsg = "The CaseCoder has been updated, please do a visual
    verification.">
    </cfif>
    <cfoutput>#CCMsg#</cfoutput>

    bikerboy Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139