Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 001D16B1A for ; Mon, 25 Jul 2011 19:38:00 +0000 (UTC) Received: (qmail 70301 invoked by uid 500); 25 Jul 2011 19:37:57 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 70226 invoked by uid 500); 25 Jul 2011 19:37:57 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 70217 invoked by uid 99); 25 Jul 2011 19:37:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jul 2011 19:37:56 +0000 X-ASF-Spam-Status: No, hits=0.7 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [193.252.22.191] (HELO smtp6.freeserve.com) (193.252.22.191) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Jul 2011 19:37:49 +0000 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf3616.me.freeserve.com (SMTP Server) with ESMTP id B4E6F7000099 for ; Mon, 25 Jul 2011 21:37:27 +0200 (CEST) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf3616.me.freeserve.com (SMTP Server) with ESMTP id A852870000FD for ; Mon, 25 Jul 2011 21:37:27 +0200 (CEST) Received: from mail.homeinbox.net (unknown [2.24.223.83]) by mwinf3616.me.freeserve.com (SMTP Server) with ESMTP id 953237000099 for ; Mon, 25 Jul 2011 21:37:27 +0200 (CEST) X-ME-UUID: 20110725193727611.953237000099@mwinf3616.me.freeserve.com Received: from localhost (localhost [127.0.0.1]) by mail.homeinbox.net (Postfix) with ESMTP id 48476EAAC32 for ; Mon, 25 Jul 2011 20:37:27 +0100 (BST) X-Virus-Scanned: Debian amavisd-new at homeinbox.net Received: from mail.homeinbox.net ([127.0.0.1]) by localhost (mail.homeinbox.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6qpt1MvrywqR for ; Mon, 25 Jul 2011 20:37:14 +0100 (BST) Received: from [192.168.23.9] (study03.dev.local [192.168.23.9]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.homeinbox.net (Postfix) with ESMTPSA id 49977EAAC30 for ; Mon, 25 Jul 2011 20:37:14 +0100 (BST) Message-ID: <4E2DC5E7.5040507@apache.org> Date: Mon, 25 Jul 2011 20:37:11 +0100 From: Mark Thomas User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-GB; rv:1.9.2.18) Gecko/20110616 Thunderbird/3.1.11 MIME-Version: 1.0 To: Tomcat Users List Subject: Re: Comet: How to send *Chunked* response References: In-Reply-To: X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit On 25/07/2011 19:23, Sudeep Pradhan wrote: > Hi, > > I am using CometProcessor to stream event notifications from server to client. The events are generated at random. I want to send the notification with Transfer Encoding as chunked so that I can use Apache's ChunkedInputStream to parse the output. > > I get the PrintWriter from the ServletResponse using the getWriter() and I write the event notification on this writer. I want this to be in chunk format of length-payload. Currently I do the following: > > PrintWriter writer = connection.getWriter(); > for (int j = 0; j < pendingEvents.length; j++) { > String eventString = converter.convert(pendingEvents[j]); > eventString.concat("\r\n"); > final String length = Integer.toHexString(eventString.length()); > writer.print("\r\n" + length + "\r\n"); > writer.print(eventString); > //logger.info("Writing:" + eventString); > } > > But this generates a Bad Chunk size exception on client. Just write and flush the content. Tomcat will handle the chunking for you. Mark --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org