Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Applet-Servlet Communication problem

Status
Not open for further replies.

itsjoker

Programmer
Feb 26, 2003
3
0
0
IT
Hi,

I am designing an applet servlet communication application. I have an applet that connects to the servlet to exchange information.

I am trying to do the following in the servlet to get ObjectInputStream of the client and it hangs there and then returns the client with "Response code 500".

ObjectInputStream oas = new ObjectInputStream(httpreq.getInputStream());

Can someone please tell me whats going on. I am trying to send a serialized object back and forth. I can read anything the servlet sends to the applet, but I am having trouble reading from the applet to the servlet.

Please help.

Regards,
guna
 
*****applet***

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import java.io.*;

public class MyApplet extends Applet {
//Initialize the applet
String printMsg="Message from Servlet..->";
TextArea txt=new TextArea(10,20);
Button submit=new Button("Submit");
Label lbl=new Label("Message from Servlet..->");
public void init() {
add(txt);
add(submit);
add(lbl);
submit.addActionListener(new Listen());
}

class Listen implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
String location =
"
URL testServlet = new URL( location );
URLConnection servletConnection =
testServlet.openConnection();
BufferedReader inputFromServlet = new
BufferedReader(new
InputStreamReader(servletConnection.getInputStream()));
String msgFromServlet=null;

while((msgFromServlet=inputFromServlet.readLine())!=null)

printMsg+=msgFromServlet;
lbl.setText(printMsg);
validate();
}catch(Exception exp){exp.printStackTrace();}
}
}
}


*****the srevlet just sends back the msg it received.*****

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class MyServlet extends HttpServlet {

//Initialize global variables
public void init(ServletConfig config) throws
ServletException {
super.init(config);
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String param=request.getParameter("Msg");
PrintWriter out = new PrintWriter
(response.getOutputStream());
out.println("Received msg.."+param);
out.close();
}
hope this might help u
 
Hi,
Thank you for your help. I was able to send stuff from the servlet back to the applet with no problem.

Can I open a input stream in the servlet to receive text or Objects from a client?

I am working on a voice application and I have to send voice packets from the applet to the server. Do you have anything in mind that could help me send this over. I see that I can send as querystring with no problem and get packets back through stream, however I want to know if there is any other way.

Thank you again.

Regards,
guna
 
Hummmmm!!!
this is bit tricky lets work on this

iam sorry i cant give right way solution!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top