[Jslib] Hello!

Daniel Aquino mr.danielaquino at gmail.com
Tue Mar 6 07:54:04 PST 2007


Well it looks like the guys on irc.mozilla.org don't really use jslib ...
shame ...

But basically to knock off my first question:

In socket.js, I'm trying to have a status light on my client application
that shows if the server connection is closed, broken! or connected...  And
basically the way it seems to work I can't seem to find a good solution to
handle that...

It's really a pain that I cant use socket.isAlive in the same stack run as
socket.open... Actually I'm not even sure what the same stack run would
be...  Why does this happen?

I tried to use the observer object for the stream-pump but that seems to
have weird results because the onStartRequest only fires after some data is
sent...

I need a viable way to detect if the connection successfully establishes or
not after I call socket.open

Any help?

Here is my server code...
http://pastie.caboo.se/private/esb08sttegqazj0jtt


  var Server = function( protocol ){
    try {
      // enablePrivilege is required if not running chrome'd
      // (other tweaks might apply, check out public.mozdev.jslib)
      netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
      include(jslib_socket);
    }catch( e ){
      dump( e );
      throw("Server object could not be created...");
    }
    this.protocol = (new protocol());
    this.open();
  }

  Server.prototype = {

    //
    // Variables
    //

    socket:    null,
    host:      "example.com",
    port:      "8080",

    //
    // Methods
    //

    open: function() {
      dump("Server: Attempting Connection... \n");
      gebi("server-status").src = "chrome://app/content/images/throbber.gif"

      if( this.socket !== undefined && this.socket !== null )
        if( this.socket.isConnected )
          return;

      this.socket = new Socket;

      var that = this;
      var observer = {
        streamStarted: function (socketContext){
          gebi("server-status").src =
"chrome://app/content/images/server_status_green_small.png"
        },
        streamStopped: function (socketContext, status){},
        receiveData:   function (data){
          dump("Server: receiveData \n");
          that.protocol.handleInput(data)
        }
      }

      // whats up with the 3rd option: binary ?
      this.socket.open( this.host, this.port, false );
      this.socket.async( observer );
    },

    close: function() {
      this.socket.close();
      gebi("server-status").src =
"chrome://app/content/images/server_status_gray_small.png"
      dump("Server: Connection Closed... \n");
    },

    send: function() {
      if( ! this.socket.isAlive() ){
        dump("Server: Could not send data, connection not alive! \n");
        return false;
      }
      //    Is there a way to transparently
      //    send arguments to another function?
      var message = this.protocol.handleOutput(arguments);
      this.socket.write( message );
      dump("Server: Sent Data... \n");
      return true;
    }

  }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mozdev.org/pipermail/jslib/attachments/20070306/0a39dc10/attachment.html 


More information about the Jslib mailing list