wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

cant read in java BufferedReader BLOCKING read #179

Closed N1Knight closed 9 years ago

N1Knight commented 9 years ago

Hi, im have a problem. the messages coming but never finish the while! The read block and never leave of while.. Any know why ??

im have this code in java:

            Writer writer = new StringWriter();
            char[] buffer = new char[1024];             
            BufferedReader  reader = new BufferedReader(new InputStreamReader(ins, "UTF-8"));
            int n;

            while((n = reader.read(buffer)) != -1){
                writer.write(buffer, 0, n);
                    System.out.println(writer.toString());
            }

my config in ngix

Push module

    location /channels-stats {

            # activate channels statistics mode for this location

            push_stream_channels_statistics;

            # query string based channel id

            push_stream_channels_path               $arg_id;

    }

    location /pub {

            # activate publisher (admin) mode for this location

            push_stream_publisher admin;

            # query string based channel id

            push_stream_channels_path    $arg_id;

            push_stream_store_messages on;

    }

    location ~ /sub/(.*) {

            # activate subscriber (streaming) mode for this location

            push_stream_subscriber;

            # positional channel path

            push_stream_channels_path                     $1;

            # message template

            push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";

    }
wandenberg commented 9 years ago

You are in a stream connection. So the client will wait until a new byte is received.

You may set a timeout on read operation or use the long polling mode, your connection will be closed at the server as soon as it sends the message to the client, and the client have to reconnect sending the proper values of the last received message. Take a look on the curl examples at the readme. On May 11, 2015 21:02, "NicoCaballero" notifications@github.com wrote:

Hi, im have a problem. the messages coming but never finish the while! The read block and never leave of while.. Any know why ??

im have this code in java:

        Writer writer = new StringWriter();
        char[] buffer = new char[1024];
        BufferedReader  reader = new BufferedReader(new InputStreamReader(ins, "UTF-8"));
        int n;

        while((n = reader.read(buffer)) != -1){
            writer.write(buffer, 0, n);
                System.out.println(writer.toString());
        }

my config in ngix

Push module

location /channels-stats {

        # activate channels statistics mode for this location

        push_stream_channels_statistics;

        # query string based channel id

        push_stream_channels_path               $arg_id;

}

location /pub {

        # activate publisher (admin) mode for this location

        push_stream_publisher admin;

        # query string based channel id

        push_stream_channels_path    $arg_id;

        push_stream_store_messages on;

}

location ~ /sub/(.*) {

        # activate subscriber (streaming) mode for this location

        push_stream_subscriber;

        # positional channel path

        push_stream_channels_path                     $1;

        # message template

        push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"tag\":\"~tag~\",\"time\":\"~time~\"}";

}

— Reply to this email directly or view it on GitHub https://github.com/wandenberg/nginx-push-stream-module/issues/179.

N1Knight commented 9 years ago

Thanks.