Using the same BufferedReader across different servlets
I tried to implement several servlets such that it allows a HTTP mode of transmitting data to a socket based server.
In the very first servlet, I made it such that a connection with the server will be established in that particular file. At the same time, I would also like the BufferedReader created in the first servlet to be used in other servlets so that I will be able to maintain the same connection with the server.
This is what I have in the first servlet:
try
{
socket =new Socket(ipName, 12111);
out =new PrintWriter(socket.getOutputStream(),true);
in =new BufferedReader(new InputStreamReader(socket.getInputStream()));
}
catch (UnknownHostException e)
{
System.err.println("Don't know about host: " + ipName);
System.exit(1);
}
catch (IOException e)
{
System.err.println("Couldn't get I/O for " +"the connection to: " + ipName);
System.exit(1);
}
I tried to use "in" in another servlet to receive data from the server but that didn't work. Note that I have already declared "out" and "in" as static.
This is what I have in the second servlet:
while (keepPolling)
{
System.out.println("Polling...");
xmlResponse = Auth.in.readLine();
if(xmlResponse !=null)
{
System.out.println("Reply: " + xmlResponse);
keepPolling =false;
}
else
{
keepPolling =true;
}
}
Problem: The code does not go past xmlResponse = Auth.in.readLine();.
Anybody able to help?
Thanks!

