|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Socket.open() returns before socket is connectedHi,
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@... http://mozdev.org/mailman/listinfo/jslib |
|
|
Re: Socket.open() returns before socket is connectedThe 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@... >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@... http://mozdev.org/mailman/listinfo/jslib |
|
|
Re: Socket.open() returns before socket is connectedHi 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 sides). 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/ fid0726D96D246710A6D8501D5F26CF178F505CF706.aspx?s=nsIInputStream - JSlib socket.js 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('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@... >> 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@... > http://mozdev.org/mailman/listinfo/jslib _______________________________________________ Jslib mailing list Jslib@... http://mozdev.org/mailman/listinfo/jslib |
| Free embeddable forum powered by Nabble | Forum Help |