Socket/Servlets Question - Please HELP!
I have a problem regarding Sockets.
What I am trying to do is : I have an applet that avoids security
issues by using servlets. The servlet opens a new socket to the server
at listens to any
new data and sends it to the applet.
the applet reads the data and manipulate it.
The problem is that the applet always read the same thing. it means
that when I read it from the socket the data stays there.
I am attaching my code, I really hope someone could help me!!!
The Servlet :
public class RT
public void doGet(HttpServletRequest request, HttpServletResponse
throws ServletException, IOException
String body = null;
String strdata = null;
PrintWriter out2Applet = null;
String Result = null;
int i = 0;
response.setContentType( "text/plain" );
body = "uid=" + request.getParameter( "uid" ) +
"&sessionid=" + request.getParameter( "sessionid" ) +
"&webip=" + request.getParameter("webip");
strdata = "POST / HTTP/1.1\nHost:
MLKHUB Version .1\nContent-Length: " +
body.length() + "\n" + "Content-Type: application/x-www-form-
urlencoded\n" + "Cache-Control: no-cache\n\n" + body + "\n" ;
socket = new Socket( "XXX.XXX.XXX.XXX", 80 );
in = new BufferedReader( (Reader) new InputStreamReader(
socket.getInputStream() ) );
out = new PrintWriter( socket.getOutputStream(), true );
out2Applet = ((ServletResponse) response).getWriter();
out.write( strdata );
out2Applet.println( strdata );
out2Applet.println( " results..." );
Result = "";
for( i = 0; i < 10; ++i )
String inputLine = in.readLine();
Result = Result.concat( inputLine );
out2Applet.write( Result );
The Reading code :
public class RTConnector
public RTConnector(Session session,String path)
m_session = session;
m_path = path;
public void run()
URL url = new URL(m_path + "RT?uid="
+ m_session.getUI().getUid() +
URLConnection con = url.openConnection();
BufferedReader in = new BufferedReader(new
String inputLine, Result = "";
while ( (inputLine = in.readLine()) != null)
Result = Result + inputLine;
Re: Socket/Servlets Question - Please HELP!
> Hi Guys,
> I have a problem regarding Sockets.
> What I am trying to do is : I have an applet that avoids security
> issues by using servlets. The servlet opens a new socket to the server
> at listens to any
> new data and sends it to the applet.
> the applet reads the data and manipulate it.
> The problem is that the applet always read the same thing. it means
> that when I read it from the socket the data stays there.
Umm... not sure what you mean by "data stays there". Can you explain
more specifically what happens? What data does it always get?
One thing I notice is that you haven't removed the headers from the HTTP
response before trying to use it. Perhaps you're seeing the first 10
lines of headers, and they happen to always be the same?
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
|All times are GMT. The time now is 05:55 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.