3 Replies Latest reply on Aug 12, 2014 4:39 AM by Trevorׅ



      I am currently writing my first InDesign/ExtendScript script. After exploring the forums, and the Object Model Viewer, it seems as if there are currently two different methods people take when performing a HTTP request. A lot of the people on the forums do the following...


      var sock = new Socket;

      // ...

      var response = sock.read(999999);


      But when using that code, it seemed to cause the main thread to halt for a large period of time (~19 seconds).

      After being puzzled as to why a simple HTTP request would take so long, I opened up the Object Model Viewer, and saw that the 'read' function's 'count' argument is optional. So I removed the argument from my code, and the request takes less than a second (with my current shoddy internet speed).


      Is there something I'm missing? Because I have not yet seen a post on the forums with anybody complaining with the above code snippet.



      Jacob Marshall

        • 1. Re: Socket#read
          Jacob_Marshall Level 1


          • 2. Re: Socket#read
            Trevorׅ Adobe Community Professional

            Hi Jacob,


            Intro 1

            I  don't know if my post will be helpful but at least it won't be less constructive than your bump.


            Intro 2

            I don't have much experience with using socket, I just use it for product activation and very small info transfer which go very quickly and I use  script by Kris which I posted a link to on a thread by your dad? which you bumped


            But as far as I gather you would only put in a count if you want to read a specific number of bytes as in the case of Kris's script, If you want to read everything you can then including a count is only going to be detrimental.  I would think that if you tell the socket to read more bytes than exist then it's going to take it's time about it.

            It probably actually finishes the reading quickly with the read(999999) method but is just looking for more to read and eventually stops with a time out.


            You could set the timeout to 1 (second) instead of the default 10 seconds and see if that cuts off from your 19 seconds.


            Either way I cant see what you have to gain by setting the socket to (99999) or the likes unless you want to limit the byte size of what you are reading (In the rare case where your address contains several Gigabytes ).  The fact that you see people using  the count is pretty meaningless, they prob got it from some bloke in a manual who got it from some other bloke from his manual who either had a good reason why he used it in his particular case or didn't.


            It is not difficult to find bad practices in print and on the web, my posting here might or might not be one.


            Please post feedback of the result of changing the timeout.  Even on the side that it doesn't cut the time it still make sense to me that it should take longer to look for the non-existing bytes but I would like to know anyway,





            • 3. Re: Socket#read
              Trevorׅ Adobe Community Professional