Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Javascript Socket Question

    Hi.
    This is my first post, so please bear with me!.
    I am writing some Javascript for some InDesign automation (shouldn't matter what for, but some background info). I have up to now been resorting to passing a script to Applescript, which then passed a shell command (via do script) to Terminal.
    This works, but is limiting my script to Mac only.
    I recently found I can open a socket, and send the PHP page my variables without leaving JavaScript..

    Here is the code I am using with the Applescript combo:
    function combinedErrorReport(errorText) //errorText is something like "Library not found"
    {
    myServerAddress = "http://automation.yappp.net/";
    errorText = encodeURI(errorText);
    myFullScriptString = "do shell script \"curl -0 "+ myServerAddress + "sendSrcError.php?e=" + errorText + "\"";
    myForceError = app.doScript(myFullScriptString, ScriptLanguage.APPLESCRIPT_LANGUAGE);
    }

    and this is what I want to use using a javascript socket...
    function combinedErrorReportWithSocket(errorText) //errorText is something like "Library not found"
    {
    myServerAddress = "automation.yappp.net:80";
    errorText = encodeURI(errorText);
    conn = new Socket();
    conn.open(myServerAddress);
    conn.write("GET /sendSrcError.php?e=" + errorText+"\ HTTP/1.0\n\n");
    reply = conn.read(999999);
    conn.close;
    }

    The socket option simply does nothing. It opens the connection, but doesn't pass anything to the PHP.

    Anyone have any ideas?

    Cheers

    Roy

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    If you have a space or various other special characters in your message, it would make sense that you wouldn't get the full data. You should surely do something like
    Code:
    conn.write("GET /sendSrcError.php?e=" + escape(errorText) + "\ HTTP/1.0\n\n");
    You might even need to use encodeUriComponent instead of just escape.

    And not to ask a dumb question, but where did you find a Socket library? One that works crossbrowser, at least?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    roystonmarshall (10-10-2011)

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Oh...and I *assume* that the web page in question is *NOT* in the domain "/automation.yappp.net", yes? Else there's no need for any of this.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi.

    Thanks for the reply.

    I am encoding the error:
    "errorText = encodeURI(errorText);"
    so there are no spaces, or other non alpha-numeric characters being passed.

    Also, I am using JavaScript in conjunction with Adobe InDesign, using Adobes ESTK. this is NOT web based, purely desktop javascript, but in this instance communicating with the PHP page on my server.

    I am not a web dev, and my JS knowledge only stretches a little way outside Adobes ESTK, but I have tried the Adobe forums with no luck.

    Thanks for the reply, maybe you have other suggestions?

    Roy

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Oh, that makes sense. I knew Adobe provided a Socket object (since some of the articles you see on using sockets from web JS tell you to do it indirectly via Adobe), so yeah, it sounds like the right approach.

    But no, I don't know the proper methods to call, etc., with that Socket object.

    No help in the Adobe forums??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    There is a guy who has been helpful in the Adobe Forum, but he has been quiete recently! Will re-post if I need to.
    The weird thing is there have been some log entries to my web page after posting the code on this forum, so someone has managed to use it somehow!

    I have tried to contact the person who did it, but still waiting. (daveyerwin)

    Out of interest the site I am trying to get my data to is:
    http://automation.yappp.net/sendSrcError.php?p=logs

    I dont want to give up, but I may have to

    Thanks anyway,

    Roy

  • #7
    Regular Coder
    Join Date
    Aug 2010
    Posts
    945
    Thanks
    19
    Thanked 205 Times in 203 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <meta name="generator" content="daveyerwin">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>SJax</title>
    
    
    
    <script type="text/javascript">
    
    req=new XMLHttpRequest();
    	req.open("GET","http://automation.*****.net/sendSrcError.php?e=hello from daveyerwin",false);
    	req.send(null);
    	alert(req.responseText);
    
    </script>
    
    </head>
    <body>
    <div id="container">
    <p>hiyas</p>
    </div> 	
    </body>
    </html>
    Last edited by DaveyErwin; 10-10-2011 at 03:05 PM.

  • Users who have thanked DaveyErwin for this post:

    roystonmarshall (10-10-2011)

  • #8
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi Davey.

    Thanks for the reply.

    I have tried your suggestion in the ESTK environment, but unfortunately the Adobe library does not support the method you are using (XMLHttpRequest).

    I will post your snippet back in the Adobe forum to see if someone there can give me a supported alternative.

    Thanks Again

    Roy


  •  

    Tags for this Thread

    Posting Permissions

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