P
paulfugl
Please help with this!
I am developing a webapplication (running on Tomcat) where a servlet in
its doGet() method opens a socket and
sends that socket's inputstream to the browser. Do I need to inplement the
serlvet as a thread, i.e. a new thread is created
every time someone triggers the doGet() method, or is this sorted out by
the servlet container itself?
My problem is that when I open a new browser window and execute that
servlet again, my app seems to lose track of where
to send the data, so the data is sent to the new browser window only. I am
using the "pushlet" concept to create a continously
stream of data to the browser.
In brief, my servlet doGet() method looks like this:
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException {
try {
oStream = new PrintWriter(response.getOutputStream());
cSocket = new Socket("127.0.0.1", 3726);
iStream = new BufferedReader(new
InputStreamReader(cSocket.getInputStream()));
while(true) {
String line = inputStream.readLine();
oStream.println(jScriptStart + " printMsg('" +
line + "');" + jScriptEnd);
oStream.flush();
}
} catch (IOException e) {
oStream.println(jScriptStart + " printMsg('" + e + "');" +
jScriptEnd);
oStream.flush();
}
}
I suspect that the compiled object is simply re-used when I make another
request, which might explain a little bit but
I have tried to make the servlet as a thread (implementing Runnable) but
same problem appeared.
Cheers,
Paul
I am developing a webapplication (running on Tomcat) where a servlet in
its doGet() method opens a socket and
sends that socket's inputstream to the browser. Do I need to inplement the
serlvet as a thread, i.e. a new thread is created
every time someone triggers the doGet() method, or is this sorted out by
the servlet container itself?
My problem is that when I open a new browser window and execute that
servlet again, my app seems to lose track of where
to send the data, so the data is sent to the new browser window only. I am
using the "pushlet" concept to create a continously
stream of data to the browser.
In brief, my servlet doGet() method looks like this:
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException {
try {
oStream = new PrintWriter(response.getOutputStream());
cSocket = new Socket("127.0.0.1", 3726);
iStream = new BufferedReader(new
InputStreamReader(cSocket.getInputStream()));
while(true) {
String line = inputStream.readLine();
oStream.println(jScriptStart + " printMsg('" +
line + "');" + jScriptEnd);
oStream.flush();
}
} catch (IOException e) {
oStream.println(jScriptStart + " printMsg('" + e + "');" +
jScriptEnd);
oStream.flush();
}
}
I suspect that the compiled object is simply re-used when I make another
request, which might explain a little bit but
I have tried to make the servlet as a thread (implementing Runnable) but
same problem appeared.
Cheers,
Paul