have this weird problem that haunting me for sometime now. the situation:
i'm using servlet tunneling technique to communicate between my C application and my Java based web application.
as shown in code below, i'm pooling the blocking read of InputStream in order to get incoming data from my remote C application.
while it working fine on Tomcat version 5.0.30 and earlier, the method doesnt seems to work on Tomcat version 5.5 and later as the read function doesnt block anymore and always return '-1' immediately (similar situation as when connection get diconnected/timeout).
any suggestion?... [ June 25, 2008: Message edited by: Ariffin Ahmad ]
Joined: Aug 16, 2001
found out the reason.
seems like i need to set Content-Length in HTTP header. but the problem that i have now is I'm intended to have a persistent socket connection, from my C application to this servlet. hence, the content length is unknown, or should i say, unlimited.
i realized that it is contrary to the HTTP style. but, i need to do it that way since i want to eliminate the headache of having to deal with firewall rules and what so ever.
custom socket programming not really practical, since i still need the tomcat to do portal hosting service for me.
lets me describe more about my situation: i have a machine at home that will keep sending events to portal. at the same time, the portal may also send some instruction to the machine. this machine will be at lots of home, and each one of them will keep updating(through events) the portal on whatever activities going on there.
the machine owner then, can access the portal and then view the updates sent by his machine. then he may send some instruction to his machine, through the portal.
i believe it is possible to assign a very large number to the content-length, but the communication between the machine and the portal will still meet the limit of the content-length at some point. and when that happen, nothing can be read on the servlet anymore.
Author and all-around good cowpoke
Joined: Mar 22, 2000
I am wondering if the Grizzly approach to server IO would solve your problem. As I understand it, it has a different implementation of request input streams.
Joined: Aug 16, 2001
thanks for the link. i will look into it.
by the way. my understanding is, HTTP 1.1 is a persistent connection by default. is there any way for me to get the main input/output stream from my servlet for that socket HTTP 1.1 connection? HttpServletRequest seems to only return input stream for request on that servlet, ie: i can only read for defined content-length and after that read() will return -1, even though HTTP 1.1 connection still there.