Return-Path: Delivered-To: apmail-jakarta-httpclient-dev-archive@www.apache.org Received: (qmail 81953 invoked from network); 12 Mar 2005 15:24:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 12 Mar 2005 15:24:57 -0000 Received: (qmail 46113 invoked by uid 500); 12 Mar 2005 15:24:56 -0000 Delivered-To: apmail-jakarta-httpclient-dev-archive@jakarta.apache.org Received: (qmail 46087 invoked by uid 500); 12 Mar 2005 15:24:55 -0000 Mailing-List: contact httpclient-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "HttpClient Project" Reply-To: "HttpClient Project" Delivered-To: mailing list httpclient-dev@jakarta.apache.org Received: (qmail 46068 invoked by uid 99); 12 Mar 2005 15:24:55 -0000 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,NORMAL_HTTP_TO_IP,RCVD_BY_IP,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of mbecke@gmail.com designates 64.233.170.201 as permitted sender) Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.201) by apache.org (qpsmtpd/0.28) with ESMTP; Sat, 12 Mar 2005 07:24:53 -0800 Received: by rproxy.gmail.com with SMTP id j1so1033128rnf for ; Sat, 12 Mar 2005 07:24:18 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=kCn24RxC9TxNbzyT09D+xOQxQku73tJz3C6rsP2jDQDFsDK/t9/XQbtnmjw5JIaPCBxzeoq2PL2epf1XHTtZU9Hq3R0o3TZ55AKKXOymf1IFO9Exqnk/vZ3kCuGGxnXKybFrgaaufLer5h+1sxLDy20O+5IVvYI116YlRpkx0LU= Received: by 10.38.208.65 with SMTP id f65mr3842228rng; Sat, 12 Mar 2005 07:24:17 -0800 (PST) Received: by 10.38.208.43 with HTTP; Sat, 12 Mar 2005 07:24:17 -0800 (PST) Message-ID: <78f7873e05031207249f95647@mail.gmail.com> Date: Sat, 12 Mar 2005 10:24:17 -0500 From: Michael Becke Reply-To: Michael Becke To: HttpClient Project Subject: Re: Asynchronous client-server communication In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable References: X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi Thomas, This may be difficult to make work since as you mention HTTP is not meant to be used this way. Have a look at EntityEnclosingMethod for how RequestEntities are used for some ideas. First off I think using chunked encoding will be a problem, so you'll want to not use that. Also, be sure to flush the output stream when you're done writing. Mike =20 On Fri, 11 Mar 2005 18:27:26 +0100, Thomas F=F6rster wrote: > Hi! >=20 > I need to implement a bidirectional, fully asynchronous client-server > communication. Normally the java.net-API would do fine, but I also have > to deal with firewalls/proxies. So I'm trying to use servlets and > HttpClient. >=20 > There are many examples of servlet-applet/application communication, but > due to the nature > of HTTP everything is a synchronous "client-sends-request > server-sends-response". >=20 > In my application client and server will have to send and receive data > from the other side > whenever they want. So I had the idea of creating two connections, one fo= r > upstream and > one for downstream. These connections will have to be kept alive during > runtime of the > client session. >=20 > That's the theory. In practice I don't get the output-stream > client->server to work. > Here's a little code I wrote with the java.net-API: In the servlet: >=20 > public void doPost(HttpServletRequest request, HttpServletResponse > response) throws IOException, ServletException { > BufferedReader in =3D new BufferedReader(new > InputStreamReader(request.getInputStream())); > while(true) { > Object l =3D in.readLine(); // read anything from = the > input stream and print it > System.out.println("recv-->"+l); > if (l=3D=3Dnull) return; > } > } >=20 > Client-side (output-stream to server): >=20 > url =3D new URL( "http://127.0.0.1/url_to_servlet" ); > URLConnection con =3D url.openConnection(); > con.setDoOutput(true); > con.setDoInput(true); > con.setUseCaches(false); > PrintWriter out =3D new PrintWriter(con.getOutputStream()); > out.println("Hello?\n"); > out.flush(); >=20 > This doesn't work. Nothing is received by the servlet. > Only when I add a >=20 > con.getInputStream(); >=20 > to the client code (after out.flush()) the servlet receives the string. > But then I cannot > use the output stream anymore. >=20 > Next I tried the HttpClient PostMethod with a RequestMethod: >=20 > HttpClient client =3D new HttpClient(); > PostMethod httppost =3D new > PostMethod("http://127.0.0.1/url_to_servlet"); > httppost.setRequestEntity(new RequestEntity() { > public void writeRequest(OutputStream out) throws IOExceptio= n > { > for (int i=3D0;i<3;i++){ > // send 3 strings with 3 seconds pause > w.println("Hello?\n"); > w.flush(); > try { > Thread.sleep(3000); > } catch (InterruptedException e) { } > } > } > [....] > } > client.executeMethod(httppost); >=20 > The result is similar. The strings are not received at once by the > servlet. Only when the > writeRequest-method returns the three strings arrive on the server-side. >=20 > What am I doing wrong? > Is that asynchronous communication possible at all? >=20 > Thank you for reading my post. > Any help appreciated. >=20 > Thomas >=20 > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org >=20 > --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org