From bmorency at newtraxtech.com Wed Jul 25 06:38:06 2007 From: bmorency at newtraxtech.com (Bruno Morency) Date: Wed, 25 Jul 2007 09:38:06 -0400 Subject: [Jslib] Socket.open() returns before socket is connected Message-ID: <9B790FB2-A3EF-4BFF-B0EC-95D28CEF5E6D@newtraxtech.com> 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 From pete at mozdevgroup.com Tue Jul 31 14:15:13 2007 From: pete at mozdevgroup.com (Pete Collins) Date: Tue, 31 Jul 2007 15:15:13 -0600 Subject: [Jslib] Socket.open() returns before socket is connected In-Reply-To: <9B790FB2-A3EF-4BFF-B0EC-95D28CEF5E6D@newtraxtech.com> References: <9B790FB2-A3EF-4BFF-B0EC-95D28CEF5E6D@newtraxtech.com> Message-ID: <46AFA661.3030003@mozdevgroup.com> 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('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 >_______________________________________________ >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