Why don't I see output on the client?
"Trustin Lee (이희승)"
trustin at gmail.com
Mon Dec 28 07:29:08 EST 2009
Hi Matt,
InputStream.read() is a blocking operation. Since it's an I/O thread
who calls your handler, executing a blocking operation will prevent the
I/O thread from flushing the write request queue which holds the write
requests you issued by calling Channel.write(). It's a sort of dead lock.
HTH,
Trustin
matt p wrote:
> Hello --
>
> I'm writing a simple server which will rebroadcast an audio stream to N
> clients.
>
> Here is my code:
>
>
> Channel channel = channelStateEvent.getChannel();
> try {
> URL url = new URL("http://audio2.radioreference.com/ca_lapd1");
> URLConnection conn = url.openConnection();
> InputStream inputStream = conn.getInputStream();
>
> ChannelBuffer buffer = ChannelBuffers.buffer(256);
> // ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
> // ChannelBufferOutputStream outputStream = new
> ChannelBufferOutputStream(buffer);
>
> int result;
> byte readbuffer[] = new byte[256];
>
> while ((result = inputStream.read(readbuffer)) != -1 ) {
>
> buffer.writeBytes(readbuffer);
> channel.write(buffer);
> buffer.clear();
> // System.out.println("writing "+ result + " bytes");
> }
>
> } catch (MalformedURLException e) {
> e.printStackTrace(); //To change body of catch statement use
> File | Settings | File Templates.
> } catch (IOException e) {
> e.printStackTrace(); //To change body of catch statement use
> File | Settings | File Templates.
> }
>
>
> Scanner server is from the example:
>
> public class ScannerServer {
>
> public static void main(String[] args) {
> ChannelFactory factory = new NioServerSocketChannelFactory(
> Executors.newCachedThreadPool(),
> Executors.newCachedThreadPool()
> );
>
> ServerBootstrap bootstrap = new ServerBootstrap(factory);
>
>
> ScannerServerHandler handler = new ScannerServerHandler();
>
> ChannelPipeline pipeline = bootstrap.getPipeline();
> pipeline.addLast("handler", handler);
> bootstrap.setOption("child.tcpNoDelay", true);
> bootstrap.setOption("child.keepAlive", true);
> bootstrap.bind(new InetSocketAddress(8888));
> }
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20091228/7e0a3ad1/attachment.bin
More information about the netty-users
mailing list