6 Replies Latest reply on Feb 4, 2013 6:47 AM by dasdeckone

    socket callback

    dasdeckone

      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