J2ME,逐行处理永无休止的http连接

发布于 2024-10-05 05:02:49 字数 619 浏览 1 评论 0原文

我必须在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花ソ最美的依靠 2024-10-12 05:02:49

使用HttpConnection似乎是不可能的,但它可以与StreamConnection一起使用

It seems to be impossible using HttpConnection, but it works with StreamConnection

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文