Manfred Haertel, DB3HM wrote:

I'm trying to work with sockets in a JavaScript program. I'm not too much experienced with Mozilla's XPCOM interface (but would like to be... ;-) ).

I found a socket programming example at http://xulplanet.com/tutorials/mozsdk/sockets.php . Unfortunately, I can't get it to work. The response returned from the remote server are never printed to the screen (in xpcshell). By adding some more print commands I get the impression that the onDataAvailable function is never called.

Can anybody tell me what's wrong with this example (or with my installation) or give me a pointer to a working example?

Thanks in advance!
_______________________________________________
Mozilla-netlib mailing list
Mozilla-netlib@mozilla.org
http://mail.mozilla.org/listinfo/mozilla-netlib


xpcshell never processes pending events on the main thread. so, if you are trying to use nsIInputStreamPump as that example does, then you will find that your OnDataAvailable callback never fires.

I have some sample code that shows how to setup the event processing properly inside xpcshell here:
http://lxr.mozilla.org/seamonkey/source/ipc/ipcd/extensions/dconnect/test/TestServer.js#54


I suggest taking runEventQ and splitting it up into two parts:

56 <http://lxr.mozilla.org/seamonkey/source/ipc/ipcd/extensions/dconnect/test/TestServer.js#56> var eqs = Components.classes["@mozilla.org/event-queue-service;1"]
57 <http://lxr.mozilla.org/seamonkey/source/ipc/ipcd/extensions/dconnect/test/TestServer.js#57> .getService(nsIEventQueueService); 58 <http://lxr.mozilla.org/seamonkey/source/ipc/ipcd/extensions/dconnect/test/TestServer.js#58> eqs.createMonitoredThreadEventQueue();



now, call AsyncRead and finally run the main event loop:

59 <http://lxr.mozilla.org/seamonkey/source/ipc/ipcd/extensions/dconnect/test/TestServer.js#59> var queue = eqs.getSpecialEventQueue(eqs.CURRENT_THREAD_EVENT_QUEUE);
60 <http://lxr.mozilla.org/seamonkey/source/ipc/ipcd/extensions/dconnect/test/TestServer.js#60> 61 <http://lxr.mozilla.org/seamonkey/source/ipc/ipcd/extensions/dconnect/test/TestServer.js#61> // this never returns
62 <http://lxr.mozilla.org/seamonkey/source/ipc/ipcd/extensions/dconnect/test/TestServer.js#62> queue.eventLoop();



this should do the trick.

-darin
_______________________________________________
Mozilla-netlib mailing list
Mozilla-netlib@mozilla.org
http://mail.mozilla.org/listinfo/mozilla-netlib

Reply via email to