result: #inputToString# [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => Boise [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 1 [islastshown] => [isfirstshown] => 1 [attachments] => [allattachments] => ) --> something went wrong. [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => BKBK [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 2 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> CFMX Socket Connection - Coldfusion - Advanced Techniques

CFMX Socket Connection - Coldfusion - Advanced Techniques

I have found myself in a situation where I need to open a Socket Connection, pass a string to a remote server, and view the server response. Gleaning information off of the web, I have been able to open the socket connection, but I haven't had any luck correctly passing the string & interpreting the response. Can any one assist me with this task? I would greatly appreciate any help you can give me in regard to the code below... <!-- begin code sample --> <cfset serverStruct = structNew() /> <!-- the variables --> <cfset URL.searchkey = "0007052"> <cfset serverStruct.serverIp ...

Sponsored Links
  1. #1

    Default CFMX Socket Connection

    I have found myself in a situation where I need to open a Socket Connection,
    pass a string to a remote server, and view the server response. Gleaning
    information off of the web, I have been able to open the socket connection, but
    I haven't had any luck correctly passing the string & interpreting the
    response.

    Can any one assist me with this task? I would greatly appreciate any help you
    can give me in regard to the code below...

    <!-- begin code sample -->
    <cfset serverStruct = structNew() />
    <!-- the variables -->
    <cfset URL.searchkey = "0007052">
    <cfset serverStruct.serverIp = #ip# />
    <cfset serverStruct.serverPort = #port# />
    <cfset serverStruct.portConnected = "" />

    <!--- Create the socket object --->
    <cfset objSocket = CreateObject("java", "java.net.Socket") />

    <!--- Connect --->
    <cftry>
    <cfset objSocket.init(serverStruct.serverIp, serverStruct.serverPort)/>

    <cfset serverStruct.portConnected = objSocket.isConnected()/>
    <!--- Did we connect? --->
    <cfif serverStruct.portConnected EQ "yes">
    <!-- create the string -->
    <cfset mySendData = '7=bol|"1,2,6,7,"|"0='&#URL.searchkey#&',"|0!;'>
    <cfset input = objSocket.getInputStream()>
    <cfset output = objSocket.getoutputStream()>
    <cfset inputToString = input.toString()>

    <!--- Close connection --->
    <cfset objSocket.close()/>
    </cfif>
    <cfcatch type="any">
    <!--- The connection wasnt made --->
    <cfset serverStruct.portConnected = "No"/>
    </cfcatch>
    </cftry>
    <cfoutput> result: #inputToString#</cfoutput>
    <!-- end code sample -->



    Sponsored Links
    Boise Guest

  2. #2

    Default Re: CFMX Socket Connection

    Hope this idea works



    <!--- Connect --->
    <cftry>
    <!--- Set up socket to IP:port of remote server --->
    <cfset objSocket.init(serverStruct.serverIp, serverStruct.serverPort)/>

    <cfset serverStruct.portConnected = objSocket.isConnected()>
    <!--- Did we connect? --->
    <cfif serverStruct.portConnected>
    <!-- create the string. Note the use of quotes to escape quotes in a string
    -->
    <cfset mySendData = "7=bol|""1,2,6,7,""|""0=" & "#URL.searchkey#" & ",""|0!;">
    <!--- obtain the streams --->
    <cfset input = objSocket.getInputStream()>
    <cfset output = objSocket.getOutputStream()>
    <!--- set up buffered reader for the socket; it will read character data
    into a buffer until until enough of it can be processed efficiently. However,
    a buffered reader reads a reader object, hence we first have to convert the
    inputstream into a reader --->
    <cfobject class="java.io.BufferedReader" name="brObj" action="CREATE"
    type="JAVA">
    <cfobject class="java.io.InputStreamReader" name="isrObj" action="CREATE"
    type="JAVA">
    <cfset streamReader = isrObj.init(input)>
    <cfset dataBuffer = brObj.init(streamReader)>
    <!--- send the data to the remote server --->
    <cfobject class="java.io.PrintWriter" name="pwObj" action="CREATE"
    type="JAVA">
    <cfset writer = pwObj.init(output)>
    <cfset sentData = writer.println(mySendData)>
    <!--- Get the response from the server --->
    <cfset response = dataBuffer.readLine()>
    </cfif>
    <!--- Close the streams and the connection --->
    <cfset streamReader.close()>
    <cfset dataBuffer.close()>
    <cfset objSocket.close()>

    <cfcatch type="any">
    something went wrong.
    </cfcatch>
    </cftry>

    BKBK Guest

  3. #3

    Default Re: CFMX Socket Connection

    BKBK,

    Thank you so much for taking the time to respond! I greatly appreciate your
    efforts.

    Unfortunately I am still getting an error [variable 'Response' is undefined].
    For some reason it does not seem to recognize the input stream. Any thoughts?



    Boise Guest

  4. #4

    Default Re: CFMX Socket Connection

    For some reason it does not seem to recognize the input stream. Any thoughts?
    The server you send a message to might not be sending a response back. Have you ruled this out?
    BKBK Guest

  5. #5

    Default Re: CFMX Socket Connection

    BKBK,

    In response to your suggestion that the server might not be responding....I
    am waiting on confirmation of the correct IP address and port information from
    the 3rd-party ASP. I will circle back with you once I hear back from them.

    Thanks again for your time and efforts!

    com

    Boise Guest

  6. #6

    Default Re: CFMX Socket Connection

    Hi Boise,

    It's a good idea, in any case, to begin the above code block by initializing the response variable, thus

    <cfset response ="">


    BKBK Guest

Similar Threads

  1. ODBC Socket Connection
    By Lynda in forum Coldfusion Database Access
    Replies: 8
    Last Post: October 26th, 01:11 PM
  2. CFMX MX7 ODBC Socket Timeout
    By CF_Jack in forum Macromedia ColdFusion
    Replies: 0
    Last Post: February 16th, 12:44 PM
  3. Help with a socket connection?
    By Martin in forum PHP Development
    Replies: 7
    Last Post: September 7th, 11:13 PM

Bookmarks

Posting Permissions

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