[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

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...

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

  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 )

      this.socket = new Socket;

      var that = this;
      var observer = {
        streamStarted: function (socketContext){
          gebi("server-status").src =
        streamStopped: function (socketContext, status){},
        receiveData:   function (data){
          dump("Server: receiveData \n");

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

    close: function() {
      gebi("server-status").src =
      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