18 Replies Latest reply on Oct 28, 2014 3:27 PM by RorohikoKris

    socket connection not returning/reading response

    bduffy323 Level 1

      Env: Indesign CS 5.5 and Indesign CS 6; Mac OS 10.8.4


      I have a strange issue with reading the response from the server that just started after a client upgraded from a previous OS to Mac OS 10.8.4. However, this particular script has worked on other 10.8.4 machines so I believe it is another issue.


      Here is the code in question:

      var rtnData = "";
      conn = new Socket;
       if (File.fs == "Windows") var isMac=0;
                else var isMac=1;
      var myRequest = "GET "+vSubDir+"/get_Pathnames.asp?ismac="+isMac+" HTTP/1.0\n\n";
      if (debug) $.writeln(myRequest);
      if (conn.open (vHost)) 
              conn.write (myRequest);       // send a HTTP request
              rtnData = conn.read(999999);  // and read the server’s reply

      vHost=I.P address of server

      vSubDir=subdirectory to the file



      So some of the tests I ran already:

      conn.open(vHost) returns true.

      When I go to vHost+vSubDir+"/get_Pathnames.asp?ismac="+isMac+" directly in the browser I receive the response I expect.



      Essentially Indesign is connecting to the server but not reading the response that I know exists. Has anyone else experienced this issue or something similiar? I can't recreate it anywhere but the client's machine.

        • 2. Re: socket connection not returning/reading response

          edit: The client has sent me a 10.8.5 OS laptap to test with and it does not work on this Mac either.


          Hey Trevor. So I downloaded thes script and tried making the socket call using the GetURL() method. Still I get no response. I decided to step through what the script was doing and it looks like it is an infinite loop because I really am getting no response. The script gets all the way down to this line:


          readState.dataAvailable = readState.buffer.length > 0;


          which returns false and then we go back through the loop.


          So this is the request that the getURL() function is using to open the socket with where the parsedURL.path and parsedURL.address are correct and are the same as being using in the browser to connect:


                  "GET /" + parsedURL.path + " HTTP/1.0\n" +

                  "Host: " + parsedURL.address + "\n" +

                  "User-Agent: InDesign ExtendScript\n" +

                  "Accept: text/xml,text/*,*/*\n" +

                  "Accept-Encoding:\n" +

                  "Connection: keep-alive\n" +

                  "Accept-Language: *\n" +

                  "Accept-Charset: utf-8\n\n";




          Not sure if it helpful but the response headers are as follows:

          1. HTTP/1.1 200 OK Cache-Control: private
          2. Content-Type: text/html
          3. Content-Encoding: gzip
          4. Vary: Accept-Encoding
          5. Server: Microsoft-IIS/8.5 Date: Thu, 20 Feb 2014 18:09:14 GMT
          6. Content-Length: 216


          I get the headers by browsing to the URL in the browser. Can anyone think of any other avenues to look at?



          EDIT #2 POST request also do not return any data. After executing the following code the reply is blank.



           if (conn.open(vHost))
              conn.write("POST " +vSubDir+"/get_pathnames.asp HTTP/1.1\r\n");
              conn.write("Host: " + vHost + "\r\n");
              conn.write("Content-Length: " + data_string.length + "\r\n");
              conn.write("Content-Type: application/x-www-form-urlencoded\r\n");
              var reply = "";
              reply = conn.read(999999);
              if (debug) $.writeln("\n----------- return from pathnames -------------\n");
              if (debug) $.writeln(reply);
              if (debug) $.writeln("\n----------- return from pathnames END -------------\n");


          Message was edited by: bduff323

          • 3. Re: socket connection not returning/reading response
            Trevorׅ Adobe Community Professional

            Hi bduff323


            Sorry I can't help you.

            All I can say is that I had a lot of problem without the script to get info from the web to indesign but with the script I have had no problems at all of sending or receiving data to a remote server on the web on both Windows and Mac.


            Maybe send Kris an invite (PM or email) to the tread to see if he can help you out.



            • 4. Re: socket connection not returning/reading response
              Trevorׅ Adobe Community Professional

              By the way this is a real good one!!


              instead of if (debug) $.writeln(....

              just do this


              DEBUG = true; // global


              function wl (s) {if (DEBUG) $.writeln(s)}



              the instead of typing if (debug) $.writeln(....) you just type wl(...)

              A lot easier on the fingers!


              possibly my most useful function

              • 5. Re: socket connection not returning/reading response
                bduff323 Level 1

                Another sanity check update:


                Its not just my socket calls that are not working. In the getURL.zip that you linked me to there was also a sample document. When I execute the script on that document none of the images get filled in so it isn't just my custom script causing this issue. It makes me wonder why more people wouldn't be experiencing this issue. I sent kris a private message but it looks like he has like 3 accounts in these forums under rorohiko. If all else fails maybe I'll tweet him a PM. Thanks for your help!

                • 6. Re: socket connection not returning/reading response
                  bduff323 Level 1

                  haha that seems like a great idea. It's not as bad as it looks on my end because I created a snippet in sublime to only have to type "con" (came from console, I'm more of a web developer) and then if ($debug) $.writeln("...") came out. But I like your solution much better and will make the change.

                  • 7. Re: socket connection not returning/reading response
                    RorohikoKris Level 2

                    Hi BDuff,


                    Haven't seen any messages. My e-mail is kris at rorohiko.com.


                    The first thing to try is to check whether anything is being transmitted. Try using Wireshark to see whether anything goes out, and whether anything comes back.


                    Also turn off any firewalls and things like Little Snitch etc... - they can complicate diagnosing things.





                    • 8. Re: socket connection not returning/reading response
                      bduff323 Level 1

                      Hi Kris, thanks for jumping in the discussion.


                      I took your advice and downloaded wireshark. I've only used it once before back in college so I'm not terribly familiar with it. What I did was just use the default capture options and start capturing. I then ran a script for a test socket call. I was expecting to see a http protocol packet from my IP to the server IP, however I did not. Any suggestions? The firewall is turned off.



                      To anyone else who views this thread that is running 10.8.5, if you can download and run the script on the sample document in http://www.rorohiko.com/podcast/geturl.zip and see if the images get filled in that would at least narrow it down to something specific to my machine/network.

                      • 9. Re: socket connection not returning/reading response
                        RorohikoKris Level 2

                        Hi BDuff,


                        I don't have an installed 10.8.x any more - I have a few 10.6, and the rest is 10.9 - so I cannot try that out. I gave 10.9 + InDesign CC a quick test, and that all seems to work fine.


                        But it sounds odd - my hunch is that there is a problem with your setup. Things I'd try:


                        * If the user is not an admin user, try again as an admin user

                        * Go and check the various logs on the machine - there might be interesting tidbits there. /var/log/system.log for example

                        * Create a brand new admin user account, log in as that user, and try again. If that works, reset your ID prefs.

                        * Run Disk Utility on startup (if I remember correctly, hold Command-R on startup) and verify/repair disk and permissions

                        * Make sure there is no confusion with multiple network adapters (e.g. Wifi vs. wired ethernet). With Wireshark it's easy to pick the wrong adapter and see nothing useful. Turn off any network adapters not relevant to the exercise via the System Preferences





                        • 10. Re: socket connection not returning/reading response
                          bduff323 Level 1

                          I am getting the same results as you are with my machines. I just can't seem to figure this one out!


                          *I operating under an admin user

                          *I checked the logs and didn't find anything too useful

                          *Created a new admin user and tried that but got the same results as previous admin user

                          *Ran the disk utility and verified the disk permissions and there were only some language files and itunes files that had mismatched permissions

                          *When using wireshark I was able to start the capture, visit google or yahoo and see the http request sent. And then during the same capture I ran the indesign script I did not see any packets being sent.


                          I also tried httpScoop with no luck either. I'm tapped out of ideas. Can you think of any other direction?

                          • 11. Re: socket connection not returning/reading response
                            RorohikoKris Level 2

                            On the slight off-chance: the one thing I forgot to ask: " 'ave you tried turning if off and on again? " - i.e. did you happen to try rebooting the machine? Nowadays, machines have such stable OS that I sometimes overlook doing a good reboot.


                            There's also all these magical 'moves': PRAM reset, power manager reset etc... You can try them for good measure, but I doubt they'll help.


                            It sounds like one of those where diagnosing it would be fun, given unlimited time and money.


                            But barring that, I'd personally haul out the big hammer - deactivate/uninstall/Adobe's CC Cleaner tool/reinstall/reactivate. And if that does not help, the even bigger hammer (OS reinstall).


                            Given that the issue started after an upgrade to the OS, I fear you might be in for the use of the even bigger hammer.


                            Not very elegant, but at some point, fixing the problem becomes more important than an accurate diagnosis 

                            • 12. Re: socket connection not returning/reading response
                              bduff323 Level 1

                              I'm happy to say that I have fixed the issue! I had to get permission from the client but after uninstalling and reinstalling Indesign everything worked just as peachy as before! So I'm not sure exactly what caused the issue in the first place but I am sure relieved that it has been resolved. Thanks for all your help guys! I atleast learned a lot along the way.

                              • 13. Re: socket connection not returning/reading response
                                Trevorׅ Adobe Community Professional

                                Glad to hear you got it sorted out. Seem's that it took you quite a while to pluck up the courage and take Kris's advice .

                                • 14. Re: socket connection not returning/reading response

                                  Note 1 :

                                  I have tried your example and it does work if I used URLs that starts with "http".


                                  In your INDD file example, the rectangle labels have "http://" prefix but when accessed using the Socket object it goes to a 302 Found which leads to a URL that has a "https://" prefix.  This has cause the sample to break.


                                  I had to use some other "http://" link (that does not redirect to a "https") to get it working.


                                  But I wonder is there a way to connect to "https" links using sockets?


                                  Side Note :

                                  I have tried Extendables: a stalwart little framework for Adobe ExtendScript but the httpRequest object does not seem to work (I keep getting 404.  Checked the link with the browser and the link loads with 200 OK).  Which lead me to this thread.


                                  Thanks a lot Kris for well thought sample

                                  • 15. Re: socket connection not returning/reading response
                                    RorohikoKris Level 2

                                    Hi Wanyuee,


                                    No, https is not part of the picture: I don't think it's feasible to write up https support on top of the Socket: I haven't tried, but I am pretty sure ExtendScript is a bit too slow for that.


                                    Sorry about that!

                                    • 16. Re: Re: socket connection not returning/reading response
                                      Trevorׅ Adobe Community Professional

                                      Hi Kris,


                                      I don't have the script in front of me but I remember thinking when a looked at it that you could speed things up by changing the result method from


                                      result += newBytes




                                      result[n++] = newBytes
                                      // ..... End of loop
                                      result = result.join("");


                                      The variable names are made up and not the ones you used but I think you get the idea.

                                      As the bytes are being read on a byte by byte basis I think the change could drastically speed things up.

                                      I have not tested this as I use the script for transferring very  small bits of info to and from the sever but I would be very surprised if the difference is not significant for transferring large quantities of data like images or InDesign Files.


                                      Just thinking out loud very much off the cuff... perhaps one could read all or most of the data at one time and process the result rather than fetching the data so many times from the server byte by byte.

                                      I'm probably way off on that one as I don't have the script in front of me and you have way more experience with this stuff than me, but it's a point to ponder.





                                      • 17. Re: Re: socket connection not returning/reading response
                                        RorohikoKris Level 2

                                        Hi Trevor,


                                        You're absolutely right. I checked the code, and it is not yet using the join() trick - it was all written before I cottoned on to that trick, and it would nearly certainly make a big difference on larger data transfers. However, it won't solve https - the hard part is writing the decryption. I don't think it is impossible, but I expect it to be slow - a lot of low-level bit manipulations going on, which is not exactly JavaScript's forte.

                                        • 18. Re: Re: socket connection not returning/reading response
                                          RorohikoKris Level 2

                                          P.S. For our own use, I've taken a different tack: I've extended our APID ToolAssistant plugin to include a full http/https stack, so I can call from ExtendScript into APID ToolAssistant and that handles the HTTPS magic. All through the magic of C++ libraries like boost and urdl. I've not exposed that information as it's more of an in-house hack, but if there is interest, I can write up a bit of documentation on it. It's not a full-fledged solution, just a very basic 'fetchURL' which supports both http and https. Call it, get data back in synchronous fashion. Not very neat or tidy, but does the trick for what I needed.