Thread: [Simpleweb-Support] Chat
Brought to you by:
niallg
|
From: berni <be...@t0...> - 2004-04-21 07:15:09
|
Hi!
I looked at Simple and thought it would be a perfect solution to create a
streaming HTML chat with it - because it does not use Servlets and because I
can create a thread in the process method. I modified the HelloService, but
the output appears only *after* the close has been issued, i.e. no
streaming. Here is my experimental code in the process method:
resp.set("Content-Type", "text/html");
out.println("<html><body><h1>Hello Service</h1>");
resp.commit();
//out.println("Hello World</body></html>");
//out.close();
new Thread(new Runnable(){
int counter = 0;
public void run() {
try {
//service.forward(req, resp);
while (true)
{
//final PrintStream out2 = resp.getPrintStream();
out.println("Hello World #" + (++counter) + "<br>");
out.flush();
//out.close();
resp.getOutputStream().flush();
resp.commit();
System.out.println("PRINTING..");
Thread.sleep(1000);
if (counter == 10)
{
out.close();
break;
}
}
}catch(Exception e){
// ....
e.printStackTrace(System.err);
}
}
}).start();
Is there any easy way to do streaming with Simple?
TIA & Regards
Bernhard
|
|
From: Niall G. <nia...@an...> - 2004-04-21 09:26:47
|
Hi,
This is a bug. I spotted this only a few days ago with the
MonitoredOutputStream, one workaround that will work is to set the
connection to close. For instance set your headers like so:
resp.set("Content-Type", "text/html");
resp.set("Connection", "close");
resp.commit();
This should enable streaming to work properly. The next release of
simple (2.4.1) which I will release shortly, will address this bug.
Niall
|
|
From: berni <be...@t0...> - 2004-04-21 09:47:11
|
Hi Niall,
thank you very much for your help. It does work now.
I just had to remove the commit because that caused a NullPointerException
on the next println.
One more thing:
Is it (technically) possible to get an exception or something if the client
stops loading the page?
Because I need to stop my thread then. Would also make sense for lengthy
database operations - if the client is gone it does not make much sense to
continue working and hogging the CPU. If I am not wrong PHP supports
something like that...
Thank you
Bernhard
----- Original Message -----
From: "Niall Gallagher" <nia...@an...>
To: <sim...@li...>
Sent: Wednesday, April 21, 2004 11:25 AM
Subject: Re: [Simpleweb-Support] Chat
> Hi,
>
> This is a bug. I spotted this only a few days ago with the
> MonitoredOutputStream, one workaround that will work is to set the
> connection to close. For instance set your headers like so:
>
> resp.set("Content-Type", "text/html");
> resp.set("Connection", "close");
> resp.commit();
>
> This should enable streaming to work properly. The next release of
> simple (2.4.1) which I will release shortly, will address this bug.
>
> Niall
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Simpleweb-Support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simpleweb-support
|
|
From: Niall G. <nia...@an...> - 2004-04-21 10:28:43
|
Hi, > Is it (technically) possible to get an exception or something if the client > stops loading the page? You should be getting an exception from the OutputStream when the client stops loading, you should be getting an IOException from the OutputStream.write or the OutputStream.flush. Let me know if this does not work. Niall |
|
From: berni <be...@t0...> - 2004-04-21 17:28:48
|
Hi Niall,
it does not work.
My Thread just continues forever...
Here is my updated code:
resp.set("Content-Type", "text/html");
resp.set("Connection", "close");
// resp.commit();
final PrintStream out = resp.getPrintStream();
final OutputStream out2 = resp.getOutputStream();
out.println("<html><body><h1>Hello Service</h1>");
// fill the browser cache
for (int i = 0; i < 3000; i++) out.print(" ");
out.print("\n");
out.flush();
new Thread(new Runnable(){
int counter = 0;
public void run() {
try {
while (true)
{
out.println("Hello World #" + (++counter) + "<br>");
out.flush();
System.out.println("PRINTING..");
Thread.sleep(1000);
/*if (counter == 10)
{
out.close();
break;
}*/
}
}catch(Exception e){
// ....
e.printStackTrace(System.err);
}
}
}).start();
Regards
Bernhard
----- Original Message -----
From: "Niall Gallagher" <nia...@an...>
To: <sim...@li...>
Sent: Wednesday, April 21, 2004 12:28 PM
Subject: Re: [Simpleweb-Support] Chat
> Hi,
>
>
> > Is it (technically) possible to get an exception or something if the
client
> > stops loading the page?
>
> You should be getting an exception from the OutputStream when the client
> stops loading, you should be getting an IOException from the
> OutputStream.write or the OutputStream.flush. Let me know if this does
> not work.
>
> Niall
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Simpleweb-Support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simpleweb-support
|
|
From: Niall G. <nia...@an...> - 2004-04-27 11:36:34
|
Hi,
Yes, this will not work as the java.io.PrintStream class does not throw
exceptions. Instead you can either add the code
if(out.checkError()) {
System.err.println("The client has closed the connection");
return;
}
Or you can wrap the OutputStream in somthing that does propagate
exceptions like the OutputStreamWriter.
Writer out = new OutputStreamWriter(resp.getOutputStream());
Hope this helps.
Niall
> Hi Niall,
>
> it does not work.
> My Thread just continues forever...
> Here is my updated code:
>
> resp.set("Content-Type", "text/html");
> resp.set("Connection", "close");
> // resp.commit();
> final PrintStream out = resp.getPrintStream();
> final OutputStream out2 = resp.getOutputStream();
> out.println("<html><body><h1>Hello Service</h1>");
> // fill the browser cache
> for (int i = 0; i < 3000; i++) out.print(" ");
> out.print("\n");
> out.flush();
> new Thread(new Runnable(){
> int counter = 0;
> public void run() {
> try {
> while (true)
> {
> out.println("Hello World #" + (++counter) + "<br>");
> out.flush();
> System.out.println("PRINTING..");
> Thread.sleep(1000);
> /*if (counter == 10)
> {
> out.close();
> break;
> }*/
> }
> }catch(Exception e){
> // ....
> e.printStackTrace(System.err);
> }
> }
> }).start();
>
> Regards
> Bernhard
>
> ----- Original Message -----
> From: "Niall Gallagher" <nia...@an...>
> To: <sim...@li...>
> Sent: Wednesday, April 21, 2004 12:28 PM
> Subject: Re: [Simpleweb-Support] Chat
>
>
> > Hi,
> >
> >
> > > Is it (technically) possible to get an exception or something if the
> client
> > > stops loading the page?
> >
> > You should be getting an exception from the OutputStream when the client
> > stops loading, you should be getting an IOException from the
> > OutputStream.write or the OutputStream.flush. Let me know if this does
> > not work.
> >
> > Niall
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by: IBM Linux Tutorials
> > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > GenToo technologies. Learn everything from fundamentals to system
> > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> > _______________________________________________
> > Simpleweb-Support mailing list
> > Sim...@li...
> > https://lists.sourceforge.net/lists/listinfo/simpleweb-support
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Simpleweb-Support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simpleweb-support
>
|
|
From: berni <be...@t0...> - 2004-04-29 18:33:52
|
Wow! Thank you very much.
This works....
Regards
Bernhard
----- Original Message -----
From: "Niall Gallagher" <nia...@an...>
To: <sim...@li...>
Sent: Tuesday, April 27, 2004 1:36 PM
Subject: Re: [Simpleweb-Support] Chat
> Hi,
>
> Yes, this will not work as the java.io.PrintStream class does not throw
> exceptions. Instead you can either add the code
>
> if(out.checkError()) {
> System.err.println("The client has closed the connection");
> return;
> }
>
> Or you can wrap the OutputStream in somthing that does propagate
> exceptions like the OutputStreamWriter.
>
> Writer out = new OutputStreamWriter(resp.getOutputStream());
>
> Hope this helps.
> Niall
>
> > Hi Niall,
> >
> > it does not work.
> > My Thread just continues forever...
> > Here is my updated code:
> >
> > resp.set("Content-Type", "text/html");
> > resp.set("Connection", "close");
> > // resp.commit();
> > final PrintStream out = resp.getPrintStream();
> > final OutputStream out2 = resp.getOutputStream();
> > out.println("<html><body><h1>Hello Service</h1>");
> > // fill the browser cache
> > for (int i = 0; i < 3000; i++) out.print(" ");
> > out.print("\n");
> > out.flush();
> > new Thread(new Runnable(){
> > int counter = 0;
> > public void run() {
> > try {
> > while (true)
> > {
> > out.println("Hello World #" + (++counter) + "<br>");
> > out.flush();
> > System.out.println("PRINTING..");
> > Thread.sleep(1000);
> > /*if (counter == 10)
> > {
> > out.close();
> > break;
> > }*/
> > }
> > }catch(Exception e){
> > // ....
> > e.printStackTrace(System.err);
> > }
> > }
> > }).start();
> >
> > Regards
> > Bernhard
> >
> > ----- Original Message -----
> > From: "Niall Gallagher" <nia...@an...>
> > To: <sim...@li...>
> > Sent: Wednesday, April 21, 2004 12:28 PM
> > Subject: Re: [Simpleweb-Support] Chat
> >
> >
> > > Hi,
> > >
> > >
> > > > Is it (technically) possible to get an exception or something if the
> > client
> > > > stops loading the page?
> > >
> > > You should be getting an exception from the OutputStream when the
client
> > > stops loading, you should be getting an IOException from the
> > > OutputStream.write or the OutputStream.flush. Let me know if this does
> > > not work.
> > >
> > > Niall
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.Net email is sponsored by: IBM Linux Tutorials
> > > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > > GenToo technologies. Learn everything from fundamentals to system
> > > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> > > _______________________________________________
> > > Simpleweb-Support mailing list
> > > Sim...@li...
> > > https://lists.sourceforge.net/lists/listinfo/simpleweb-support
> >
> >
> >
> > -------------------------------------------------------
> > This SF.Net email is sponsored by: IBM Linux Tutorials
> > Free Linux tutorial presented by Daniel Robbins, President and CEO of
> > GenToo technologies. Learn everything from fundamentals to system
> > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> > _______________________________________________
> > Simpleweb-Support mailing list
> > Sim...@li...
> > https://lists.sourceforge.net/lists/listinfo/simpleweb-support
> >
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
> For a limited time only, get FREE Ground shipping on all orders of $35
> or more. Hurry up and shop folks, this offer expires April 30th!
> http://www.thinkgeek.com/freeshipping/?cpg=12297
> _______________________________________________
> Simpleweb-Support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simpleweb-support
|