• Post Reply Bookmark Topic Watch Topic
  • New Topic

IOexception in Applet-servlet communication  RSS feed

 
mohamed zafer
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,
I want my applet to communicate with a servlet. and hence I use URLConnection and the corresponding IOStreams for that. But a IOException is getting raised.
THe Code is as follows
URL url = new URL("http://10.10.1.78:8080/servlet/SysServer");
String qry = URLEncoder.encode("qry") + "=" + URLEncoder.encode(qryString);
URLConnection uc = url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
uc.setRequestProperty("Content-type","application/x-www-form-urlencoded");
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
dos.writeBytes(qry);
dos.flush();<----Here
dos.close();
ObjectInputStream oin = new ObjectInputStream(uc.getInputStream());<---Here
AN IOException is getting raised. at the lines pointed cby "<----Here". The puzzling thing is that the Exception is getting raised at out.flush() and not at the creation of the ouputstream. and I comment the Flush() line ,it is thrown at
uc.getInputStream().
What is the Possible cause
Please act fast

Zafer
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've seen this when the server wasn't available for some reason. Try and code an html page to do the post to the server. Work on getting the server running properly with this, then try your code. I don't see any thing wrong with it. However if the server is available and you still get this, let me know and include the qryString.
Hope this helps
 
mohamed zafer
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Carl,
I tried your solutoin ,but it was giving the same exception.
When I tried creating the URL using getPort() and getHost(), I found that the applet is in port 80 while the server is in port 8080. I could'nt sort out the reason for the differences in port number. THen I tried copying and modifying the phone example from the JavawebServer, and it worked fine. Now I am continueing with that and it is working fine
Thank you ponce again and let me know if you come to know the reason.
Zafer
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!