[Jslib] Socket.open() returns before socket is connected

Bruno Morency bmorency at newtraxtech.com
Wed Aug 1 07:06:18 PDT 2007

Hi Pete,

I could not get my problem fixed so I wrote 2 libraries for my needs  
on Monday. There's a client socket and a server socket. I need those  
libraries for an application where the interface (XUL) needs to  
communicate with external hardware modules through local sockets (the  
hardware module is abstracted by an executable which handles  
communication with the interface commands can be made from either  

Disclaimer : Server socket only listens to local connections and  
works with one-line commands. Libraries seems to work great but they  
are a first draft.

I attached the libraries (renamed as .txt files) and usage examples,  
feel free to use and submit improvements.

Bruno Morency

PS :
Libraries built using the following as references :
- http://www.xulplanet.com/tutorials/mozsdk/sockets.php
- http://www.xulplanet.com/tutorials/mozsdk/serverpush.php
- http://www.koders.com/javascript/ 
- JSlib socket.js

-------------- next part --------------
A non-text attachment was scrubbed...
Name: socketLibs.zip
Type: application/zip
Size: 5163 bytes
Desc: not available
Url : http://mozdev.org/pipermail/jslib/attachments/20070801/eacc2d52/attachment.zip 
-------------- next part --------------

On 07-07-31, at 17:15, Pete Collins wrote:

> The socket code is older and may need some updating. I'll have a  
> look asap.
> Thanks
> --pete
> Bruno Morency wrote:
>> Hi,
>> I'm trying to use the socket module of jslib and there's something I
>> don't get with the open() method, it seems to return before the
>> socket is actually connected and a write() called immediatly after
>> the open() throws "Socket.write: Not Connected." exceptions. Is there
>> any way to make sure the socket is really connected when Socket.open
>> () returns? If not, how do I passed function to be called when it is
>> (Socket.async() doesn't seem to work with Socket.open())?
>> What I want to do :
>> var mysock = new Socket();
>> mysock.open('',3333);
>> mysock.write("some command\n");
>> This almost always throws "Socket.write: Not Connected." exceptions.
>> However, if a put a manual pause between open() and write(), it works
>> all right :
>> var mysock = new Socket();
>> mysock.open('',3333);
>> alert('pause, press OK to return');
>> mysock.write("some command\n");
>> That's what make me believe the problem with the first code snippet
>> is not that there is a problem with the code or the deamon listening
>> on port 3333 but the fact that open() return before the socket is  
>> ready.
>> Anyone knows how to have Socket.open() block until the socket we are
>> connecting to is connected?
>> Thanks
>> Bruno
>> _______________________________________________
>> Jslib mailing list
>> Jslib at mozdev.org
>> http://mozdev.org/mailman/listinfo/jslib
> -- 
> Pete Collins - Founder, Mozdev Group Inc.
> www.mozdevgroup.com
> Mozilla Software Development Solutions
> tel: 1-719-302-5811
> fax: 1-719-302-5813
> _______________________________________________
> Jslib mailing list
> Jslib at mozdev.org
> http://mozdev.org/mailman/listinfo/jslib

More information about the Jslib mailing list