Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.
-
bikerboy #1
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
-
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... -
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... -
<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... -
cfscript and variables
I'm using cfscript against a COM object. In VB the paramater is passed like: Set oSegment = oTransactionset.CreateDataSegment('BEG')... -
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: ... -
PaulH #2
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
-
bikerboy #3
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
-
PaulH #4
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
-
bikerboy #5
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
-
PaulH #6
Re: cfscript
um, don't forget logic to close the socket if everything went ok & the connection is no longer needed.
PaulH Guest
-
bikerboy #7
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



Reply With Quote

