Skip to main content
February 4, 2013
Question

socket callback

  • February 4, 2013
  • 1 reply
  • 1103 views

hi there.

i want my scrip to react on messages from a socket.

i tried something like this.

Test.prototype.constructor = Test;

function Test()

{

    this.socket = new Socket;

    this.socket.timeout = 10;

    var con = this.socket.open("127.0.0.1:9876","UTF-8");

}

Test.prototype.test = function()

{

    var target = 'indesign-8.0';

    var m = new BridgeTalk();

    m.target = 'indesign-8.0';

  

   

        while(true)

    {

       

        var res = this.socket.read();

        if(res.length > 0)

        {

         m.send();

            alert(res);

            }

            else

            $.sleep(50);

    }

    Model.init();

}

var t = new Test();

t.test();

this kind of works. an "alert" is shwon every time i send a message from the other side.

but the while loop will block everything else. is there a way to prevent this?

i also had the idea to implement a threaded socket in a c++ library, but it seems i can non use callbacks from an external object?

i can not see a way of calling a javascript function from my c++ library. i can only react on calls.

please ask if i'm not clear as to what i'm trying to do.

cheers

jm

This topic has been closed for replies.

1 reply

TᴀW
Legend
February 4, 2013

Try socket.listen() rather than socket.open().

I don't have much experience using sockets, but HTH.

Ariel

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators
February 4, 2013

thanks a lot ...but afaict listen is to listen to incoming connections. not what i want, as i have to have an open connection to begin with...but i'll try it never the less. thanks

jm

TᴀW
Legend
February 4, 2013

Have a good look at the Javascript Tools Guide CS6 (or 5 or 4) under the

chapter on "External Communications". The pdf is available under the

help menu in ESTK.

Ariel

id-extras.com | InDesign tools & scripts for typesetters, form designers, and translators