Friday, September 26, 2008

constructor issues with http connection

Two posts ago I was talking about how I had to generate the content-length info before I opened the http connection in talkLock.  Actually, the issue was subtler than that, but does make sense :)

Before you feed your OutputStream to your connection object as an argument, you need to set all of your http header information (like content-length, content-type, &c).  This is because passing the stream to the object calls a constructor to run, and build your connection, including the headers.  Trying to assign values after the constructor runs doesn't do anything for the connection that has already been started.

To my surprise the Knudsen book didn't say anything about this!  I wonder if Jonathan knows but never got around to mentioning it in the book.  That's probably the case, he's really freaking smart.

Anyway, turns out that the last release of talkLock does POST, but the data that gets POSTed is zero bytes.  Haven't fixed that yet, and frankly, I'm scratching my noggin on this one.  My tcpdumps on the web server show the data, but it never makes it to http land.  Hruhh?  Dunno.

Also the copy of talk.php that I put on Sourceforge in the last release (talk.php is the server side script) is broken.  It doesn't work at all :(  It's probably safe to get everything from marmot.

No comments: