Thanks, Filip, for your time on this! I used your changes and still get an END event. With your changes the client and socket are definitely staying alive now. I stepped through the client code and see the end event appear on the server as soon as I step through the line that writes the 0crlfcrlf:
byte[] outputBytes = new String("0" + DELIMITER + DELIMITER).getBytes(ENCODING); --> outputStream.write(outputBytes); // end event appears after this line Anyway, I don't want to take up any more of your time on this. I'm using non-chunked httpurlconnections now, which are working fine for me with comet. I just wanted to let you know the behavior I'm seeing on my machine. It's possible there are problems with my test, but you've got the code I'm using. Maybe there's a configuration difference on our tomcats? If you want to pursue this further, let me know, and I'm happy to get you any more information you need. Otherwise, I appreciate your time and thanks for all your work on tomcat! Peter On Jan 22, 2008 2:37 PM, Filip Hanik - Dev Lists <[EMAIL PROTECTED]> wrote: > your test client is wrong,I've pasted in the correct one > > only three changes > 1. set the timeout so that the socket stays alive > 2. keep reading data so that the socket stays alive > 3. 0crlfcrlf as the last chunk > > works as expected. to make a workable client, it should read until it > gets the last-chunk, not read forever like I am doing. I just didn't see > the need to put in http parsing in the code to demonstrate it. > > also, I applied the timeout patch that I wrote about earlier,so I am > setting the timeout in the comet servlet, without the patch its using > the connectionTimeout value > > package test; > > import java.io.IOException; > import java.io.InputStream; > import java.io.OutputStream; > import java.net.NoRouteToHostException; > import java.net.Socket; > import java.net.URL; > > public class TestClient { > > private static final String ENCODING = "ISO-8859-1"; > > private static final String DELIMITER = "\r\n"; > > private URL url; > > private InputStream inputStream; > > private OutputStream outputStream; > > private Socket socket; > > public static void main(String[] args) throws Exception { > TestClient test = new TestClient(); > test.test(); > } > > private void test() throws Exception { > url = new URL("http://localhost:8080/comet"); > initConnection(); > sendHeaders(); > send("comet test"); > // uncomment sleep to get END event instead of read error > // try { > // Thread.sleep(50); > // } catch (InterruptedException ie) { > // // do nothing > // } > sendLastChunk(); > // block on read to keep app alive - server never sends response > byte[] data = new byte[8192]; > int result = inputStream.read(data); > > while (result>0) { > String s = new String(data,0,result); > System.out.println("Received data:\n"+s); > result = inputStream.read(data); > } > { > System.out.println("Received EOF"); > } > } > > private void initConnection() throws IOException { > int port = url.getPort(); > port = (port < 0) ? url.getDefaultPort() : port; > try { > socket = new Socket(url.getHost(), port); > socket.setSoTimeout(Integer.MAX_VALUE); > > socket.setKeepAlive(true); > inputStream = socket.getInputStream(); > outputStream = socket.getOutputStream(); > } catch (NoRouteToHostException nrthe) { > System.out.println("host: " + url.getHost()); > nrthe.printStackTrace(); > } > } > > private void sendHeaders() throws IOException { > String path = url.getPath(); > StringBuffer outputBuffer = new StringBuffer(); > outputBuffer.append("POST " + path + " HTTP/1.1" + DELIMITER); > outputBuffer.append("Host: " + url.getHost() + DELIMITER); > outputBuffer.append("User-Agent: CometTest" + DELIMITER); > outputBuffer.append("Connection: keep-alive" + DELIMITER); > outputBuffer.append("Content-Type: text/plain" + DELIMITER); > outputBuffer.append("Transfer-Encoding: chunked" + DELIMITER); > outputBuffer.append(DELIMITER); > byte[] outputBytes = outputBuffer.toString().getBytes(ENCODING); > outputStream.write(outputBytes); > outputStream.flush(); > } > > private void send(String chunkData) throws IOException { > byte[] chunkBytes = chunkData.getBytes(ENCODING); > String hexChunkLength = Integer.toHexString(chunkBytes.length); > StringBuffer outputBuffer = new StringBuffer(); > outputBuffer.append(hexChunkLength); > outputBuffer.append(DELIMITER); > outputBuffer.append(chunkData); > outputBuffer.append(DELIMITER); > byte[] outputBytes = outputBuffer.toString().getBytes(ENCODING); > outputStream.write(outputBytes); > outputStream.flush(); > } > > private void sendLastChunk() throws IOException { > byte[] outputBytes = new String("0" + > DELIMITER+DELIMITER).getBytes(ENCODING); > outputStream.write(outputBytes); > outputStream.flush(); > } > } > > > Peter Warren wrote: > > Just to make sure that I wasn't crazy, I did some more tests, > > including using your cometgui.jar. My results still show both read > > errors and END events. Is it possible that it's a platform issue? > > I'm running Windows XP Pro SP2. As I mentioned before I'm using the > > tomcat 6.0.x trunk as of 21-01-2008. Also, I re-started tomcat in > > between all tests to make sure there weren't stray bytes hanging > > around somewhere. My server code is the same as shown previously in > > this thread. > > > > Peter > > > > Here are my results: > > > > 1) Running LastChunkTest (code below) with last chunk of 0crlfcrlf, > > server shows: > > > > event: BEGIN, subtype: null > > event: READ, subtype: null > > Read 10 bytes: comet test for session: 627378C9DEE2817A93EBAC190DE47599 > > read error > > > > 2) Running LastChunkTest with last chunk of 0crlfcrlf and a 50 ms > > sleep before sending last chunk, server shows: > > > > event: BEGIN, subtype: null > > event: READ, subtype: null > > Read 10 bytes: comet test for session: A00EFFC9A9FE8CBF1833D204EF00667C > > event: END, subtype: null > > > > 3) Running LastChunkTest with a last chunk of 0crlf, server shows: > > > > event: BEGIN, subtype: null > > event: READ, subtype: null > > Read 10 bytes: comet test for session: DD41C198E3D5CD6E7D73FC0D7B37E86F > > > > 4) Running cometgui.jar with 0crlfcrlf: > > > > client sends (without the dashes): > > > > --------------------------------------------------------------------- > To start a new topic, e-mail: users@tomcat.apache.org > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]