code does not work properly when i remove alert

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

code does not work properly when i remove alert

sugar_lisp
Hi

I am facing a strange problem, in the code below when i remove alert statement the client socket does not send data to the server. I have read some forums on this problem and they mentioned about giving some time delay but it does not work.

var transportService = Components.classes["@mozilla.org/network/socket-transport-service;1"].getService(Components.interfaces.nsISocketTransportService);
var transport = transportService.createTransport(null,0,'127.0.0.1',4444,null);
var outstream = transport.openOutputStream(0,0,0);
alert('Sending Data'); //when i remove this statement the code does not work properly

var len = y.length+'\n'+'';
outstream.write(len,len.length);
outstream.write(y,y.length);
outstream.flush();

Please do let me know the solution to this problem.
Reply | Threaded
Open this post in threaded view
|

Re: code does not work properly when i remove alert

Pavol Mišík
sugar_lisp wrote:

> Hi
>
> I am facing a strange problem, in the code below when i remove alert
> statement the client socket does not send data to the server. I have read
> some forums on this problem and they mentioned about giving some time delay
> but it does not work.
>
> var transportService =
> Components.classes["@mozilla.org/network/socket-transport-service;1"].getService(Components.interfaces.nsISocketTransportService);
> var transport =
> transportService.createTransport(null,0,'127.0.0.1',4444,null);
> var outstream = transport.openOutputStream(0,0,0);
> alert('Sending Data'); //when i remove this statement the code does not work
> properly
>
> var len = y.length+'\n'+'';
> outstream.write(len,len.length);
> outstream.write(y,y.length);
> outstream.flush();
>
> Please do let me know the solution to this problem.

Honestly I never used it.
But taking a look at
http://mxr.mozilla.org/mozilla1.9.2/source/netwerk/base/public/nsISocketTransport.idl#47

If I were you I would try to write you own class that implements
nsITransportEventSink, set it to transport, by setEventSink before you
call openOutputStream and then wait till you get status STATUS_CONNECTED_TO.

PM-
_______________________________________________
dev-apps-js-debugger mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-js-debugger
Reply | Threaded
Open this post in threaded view
|

Re: code does not work properly when i remove alert

Gijs Kruitbosch ("Hannibal")
In reply to this post by sugar_lisp
On 26/02/2010 00:57 AM, sugar_lisp wrote:

>
> Hi
>
> I am facing a strange problem, in the code below when i remove alert
> statement the client socket does not send data to the server. I have read
> some forums on this problem and they mentioned about giving some time delay
> but it does not work.
>
> var transportService =
> Components.classes["@mozilla.org/network/socket-transport-service;1"].getService(Components.interfaces.nsISocketTransportService);
> var transport =
> transportService.createTransport(null,0,'127.0.0.1',4444,null);
> var outstream = transport.openOutputStream(0,0,0);
> alert('Sending Data'); //when i remove this statement the code does not work
> properly
>
> var len = y.length+'\n'+'';
> outstream.write(len,len.length);
> outstream.write(y,y.length);
> outstream.flush();
>
> Please do let me know the solution to this problem.

Define "Does not work properly"? Exception? Error message? Code runs fine but
server doesn't get the data? What's going on?

 From reading the IDL, your problem may be solved by passing the OPEN_BLOCKING
flag
(http://mxr.mozilla.org/mozilla1.9.2/source/netwerk/base/public/nsITransport.idl#104),
although I too don't know this code, and am just guessing. Try asking in
m.d.platform instead (setting followupto). Alternatively, search for
openOutputStream in MXR to find a working example.

~ Gijs
_______________________________________________
dev-apps-js-debugger mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-apps-js-debugger
Reply | Threaded
Open this post in threaded view
|

Re: code does not work properly when i remove alert

sugar_lisp
In reply to this post by sugar_lisp
Does not work properly means code does get executed but the server does not get the message. When I place the alert statement as shown below then the sever gets the message.

Thank you for your time.

sugar_lisp wrote
Hi

I am facing a strange problem, in the code below when i remove alert statement the client socket does not send data to the server. I have read some forums on this problem and they mentioned about giving some time delay but it does not work.

var transportService = Components.classes["@mozilla.org/network/socket-transport-service;1"].getService(Components.interfaces.nsISocketTransportService);
var transport = transportService.createTransport(null,0,'127.0.0.1',4444,null);
var outstream = transport.openOutputStream(0,0,0);
alert('Sending Data'); //when i remove this statement the code does not work properly

var len = y.length+'\n'+'';
outstream.write(len,len.length);
outstream.write(y,y.length);
outstream.flush();

Please do let me know the solution to this problem.
Reply | Threaded
Open this post in threaded view
|

Re: code does not work properly when i remove alert

sugar_lisp
Thanks both of you. I changed the code as follow

var outstream = transport.openOutputStream(1,0,0); //blocking mode and it works fine



sugar_lisp wrote
Does not work properly means code does get executed but the server does not get the message. When I place the alert statement as shown below then the sever gets the message.

Thank you for your time.

sugar_lisp wrote
Hi

I am facing a strange problem, in the code below when i remove alert statement the client socket does not send data to the server. I have read some forums on this problem and they mentioned about giving some time delay but it does not work.

var transportService = Components.classes["@mozilla.org/network/socket-transport-service;1"].getService(Components.interfaces.nsISocketTransportService);
var transport = transportService.createTransport(null,0,'127.0.0.1',4444,null);
var outstream = transport.openOutputStream(0,0,0);
alert('Sending Data'); //when i remove this statement the code does not work properly

var len = y.length+'\n'+'';
outstream.write(len,len.length);
outstream.write(y,y.length);
outstream.flush();

Please do let me know the solution to this problem.