Try not opening the inbound message stream in the
client until you've written and closed the outbound stream.
I think that when you open the inbound stream, the underlying
socket connection is made and the data currently on the
outbound stream is sent. Thus, if you open the inbound stream
*before* writing your outbound message... nothing goes out.
(I'm not 100% sure abou this - I researched this problem
more when I was trying to get it to work, but once I found
a stable way I left it alone).
-Mike
----- Original Message -----
From: "Ritin Mathur" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 24, 2001 4:59 PM
Subject: Re: Application - Servlet communication using sockets
> hi
>
> Mike and Chrstopher, thanks for the help ...
>
> my application can now call the servlet and pass on
> headers to it ... the archives
> were a great source of ideas and links for further
> information ... thanks ...
> I have pasted the code for the servlet and the
> application code right at the end
> (for others who may need to do the same thing..)
>
> There is another problem that I am facing, my
> application obtains the output stream and
> writes to the servlet ... but at the other end, the
> servlet is getting a value of null... I take
> the applications input and output streams as :
>
> PrintWriter out=new
> PrintWriter(hconn.getOutputStream());
> BufferedReader in=new BufferedReader(new
> InputStreamReader(hconn.getInputStream()));
> out.println(message);
>
> and i take the servlets input stream as :
>
> PrintWriter out=new
> PrintWriter(request.getOutputStream());
> BufferedReader in=new BufferedReader(new
> InputStreamReader(request.getInputStream);
> message = in.readLine();
> System.out.println("the message is :"+message);
>
>
> The output of this is coming to be NULL .. i.e, the
> message object is becoming null...
> i saw a code sample which encoded the strings before
> sending them by using the encode()
> method of the URLEncoder class ... i tried that out
> but that also doesnt seem to work ...
> please take a look at the code, right at the end ...
>
> Thanks for yr help and consideration ...
>
> Regards,
>
> Ritin Mathur
>
> P.S. Christopher, thanks for the link to the
> HTTPClient library ... it looks pretty neat ... i'll
> be trying it out, once i get this damn thing working
> ...
>
>
>
>
>
>
>
>
>
>
>
> ************************************************************
> THE APPLICATION PROGRAM
>
> import java.net.*;
> import java.io.*;
>
> public class application
> {
> public static void main(String args[]) throws
> Exception
> {
> System.out.println("Connecting to the
> servlet...");
> URL url = new
> URL("http://localhost:8080/servlet/myservlet");
> HttpURLConnection
> hconn=(HttpURLConnection)url.openConnection();
>
> hconn.setDoOutput(true);
> hconn.setDoInput(true);
> hconn.setRequestMethod("GET");
> hconn.setRequestProperty("name","ritin");
> // hconn.connect();
>
> PrintWriter out=new
> PrintWriter(hconn.getOutputStream());
> BufferedReader in=new BufferedReader(new
> InputStreamReader(hconn.getInputStream()));
>
> String message = URLEncoder.encode("ritin
> mathur");
> out.println(message);
> out.flush();
> out.close();
> in.close();
> hconn.disconnect();
>
> }
> }
> ************************************************************
> THE SERVLET PROGRAM
>
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.io.*;
>
> public class myservlet extends HttpServlet
> {
> public void doGet(HttpServletRequest
> request,HttpServletResponse response)throws
> ServletException,IOException
> {
> System.out.println("Inside the servlet...");
> System.out.println("called by the
> application...");
> //String value = request.getParameter("name");
> String value = request.getHeader("name");
> System.out.println("value is "+value);
>
> BufferedReader in=new BufferedReader(new
> InputStreamReader(request.getInputStream()));
> String message = "mathur";
> message = in.readLine();
> System.out.println(message);
> in.close();
> }
>
> public void doPost(HttpServletRequest
> request,HttpServletResponse response)throws
> ServletException,IOException
> {
> doGet(request,response);
> }
> }
>
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html