J2ME,逐行处理永无休止的http连接
我必须在 J2ME 中编写一个简单的 http 连接读取器,它必须逐行处理分块连接。
我尝试了这个:
connection = (HttpConnection) Connector.open( url );
inputStream = connection.openDataInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c ;
while (true) {
c = inputStream.read();
if (c == -1)
break;
if (c == 10) { // new line \n
handler( baos.toString() );
baos = new ByteArrayOutputStream();
}
else
baos.write(c);
}
但似乎只有当服务器关闭连接时才启动整个过程。
我如何管理新的传入线路而不必缓冲所有内容?
谢谢你!
I have to write a simple http connection reader in J2ME who has to process a chunked connection line by line.
I tried this:
connection = (HttpConnection) Connector.open( url );
inputStream = connection.openDataInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int c ;
while (true) {
c = inputStream.read();
if (c == -1)
break;
if (c == 10) { // new line \n
handler( baos.toString() );
baos = new ByteArrayOutputStream();
}
else
baos.write(c);
}
but it seems to start the entire process only when the server close the connection.
How do i have to manage new incoming lines without have to buffer everything ?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用HttpConnection似乎是不可能的,但它可以与StreamConnection一起使用
It seems to be impossible using HttpConnection, but it works with StreamConnection