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

Bruno Morency bmorency at newtraxtech.com
Wed Jul 25 06:38:06 PDT 2007


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('127.0.0.1',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('127.0.0.1',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


More information about the Jslib mailing list