Git Product home page Git Product logo

netty-in-action's Introduction

This Repository contains the source-code for all chapters of the book Netty in Action by Norman Maurer and Marvin Allen Wolfthal.

Latest version: https://github.com/normanmaurer/netty-in-action/tree/2.0-SNAPSHOT

Enjoy! Feedback and PR's welcome!

Prerequisites

JDK 1.7.0u71 or better

Maven 3.3.9 or better

If you want to build everything at once, from the top directory run

mvn install

If you want to build only single projects then from the top directory first run

mvn install -pl utils

This will make the utils jar available to all the projects.

netty-in-action's People

Contributors

ddossot avatar favorlock avatar he-pin avatar leogomes avatar mwolfthal avatar normanmaurer avatar ssserj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

netty-in-action's Issues

About multiple Clients

if I have hundreds of client。 for this code "bootstrap.group(ctx.channel().eventLoop())"
they use one eventLoop 。 will it affect performance ?

Netty In Action sample code

As per the book, there should be a separate Maven sub module for each chapter. But it is a flat structure in the Github. Due to this inconsistency, the instructions for running some of the examples (e.g. ch.2) are invalid.

Chapter 2 Echo Client/Server takes long to startup

The following takes quite a few seconds to instantiatie class io.netty.channel.socket.nio.NioServerSocketChannel

Thread [main] (Suspended)   
    AbstractBootstrap$BootstrapChannelFactory<T>.newChannel() line: 445 
    ServerBootstrap(AbstractBootstrap<B,C>).initAndRegister() line: 298 
    ServerBootstrap(AbstractBootstrap<B,C>).doBind(SocketAddress) line: 273 
    ServerBootstrap(AbstractBootstrap<B,C>).bind() line: 237    
    EchoServer.start() line: 41 
    EchoServer.main(String[]) line: 57  

The same place (line 445) takes a long to instantiate the class for the echoclient too.
Loading class io.netty.channel.socket.nio.NioSocketChannel
Why could it possible take so long?
It does eventually run and communicate.

Using JDK 1.7 latest update
Netty netty-4.1.0.Beta3

-chhil

Maybe something wrong in demo

in chapter13/LogEventDecoder.java
it's about line 27 and 28

If i test the code,it will be go wrong
I found that there had a wrong index of ByteBuf, the code should be like that:

String logMsg = data.slice(idx + 1,
 data.readableBytes() **- idx - 1**).toString(CharsetUtil.UTF_8);

p.s.netty.vesion 5.0.0.Alpha2

confused about file wrapper depends on protocol

if (ctx.pipeline().get(SslHandler.class) == null) {
ctx.write(new DefaultFileRegion(
file.getChannel(), 0, file.length()));
} else {
ctx.write(new ChunkedNioFile(file.getChannel()));
}

ctx.pipeline().get(SslHandler.class) == null checks whether HTTPS is enabled.
The difference between new DefaultFileRegion(file.getChannel(), 0, file.length()) and new ChunkedNioFile((file.getChannel())) is that the previous one would use zero-copy optimization, which is beneficial to performance if possible.
But how shall the protocol(TLS or not) determine the usage of optimization?

Chapter12 Websocket in pending 101 switching protocols status

I was able to build the jar and deploy to a linux server.
when i hit the ip:port it shows me the index.html file
Now i hit connect and i can see the status change to 101 switching protocol
i tried to send a message. it says message not sent in the log section then i see a response with the message i sent.
i also see it in the frames.
is that expected ?


below is related to websocket sample in netty.io site.

so i decided to run the examples in the netty.io site which is just supposed to return uppercase of the message.
this one worked on a linux machine, but kept getting error 400 on a solaris machine with chrome only saying that (opcode 1) in the frames. Then i tried wireshark, there i was able to see error message saying "upgrade" is missing.
so i inspected the headers and matched up against the rfc and all the header were there.
Any ideas ?

that sample i had 2 different experiences, i export the jar and ran it as a independent jar on a windows and linux pc no issues.
when i run it directly from eclipse it got suck unable to send any message when i debugged it said it failed at the point where it was trying get the web socket version from header. At this point i saw hat the constant defined or header value was all lowercase but the hearder had uppercase in it.

Not sure how that worked when when i ran it outside of eclipse.

Something wrong in Book

in MEAP V10 BOOK
In page 69
"4. Store the currebt writerIndex." may be "4. Store the current writerIndex."

API not compatible?

Hi there~
I'm a newbie to Netty. I just want to try some example code in the book. BUT unfortunately when I set all the dependencies up, I got some problems that seems to be an API incompatible issue.
I'm using exactly the same vesion of Netty as the author Norman.

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.12.Final</version>
</dependency>

But I got this when I'm writing the echo server, I found that ServerBootstrap$group() method is deprecated, hence the channel() method and methods after that are all unavailable.

EventLoopGroup group

It's really afflictive to someone who are new to this framework. Hopefully I get some help from here!

WebSocket Client not connecting to server

I followed the code exactly(netty-in-action) and from the client side(interface included in the code of chapter 11) i wasn't able to connect to the netty chatserver.
the url i entered was ws://localhost:9099 in the client browser interface and it couldn't connect
image

the server code is taken from
https://github.com/normanmaurer/netty-in-action/tree/master/src/main/java/com/manning/nettyinaction/chapter11

and the client interface is taken from
https://github.com/normanmaurer/netty-in-action/tree/master/src/main/resources

corrigendum: table 6-1

image

here It should be read as

Channel was unregistered from the EventLoop, may be registered again if not closed.

chapter12 mvn -PSecureChatServer clean package exec:exec Exception in thread "main" java.security.cert.CertificateException: No provider succeeded to generate a self-signed certificate

mvn -PSecureChatServer clean package exec:exec
Exception in thread "main" java.security.cert.CertificateException: No provider succeeded to generate a self-signed certificate. See debug log for the root cause.
at io.netty.handler.ssl.util.SelfSignedCertificate.(SelfSignedCertificate.java:157)
at io.netty.handler.ssl.util.SelfSignedCertificate.(SelfSignedCertificate.java:110)
at io.netty.handler.ssl.util.SelfSignedCertificate.(SelfSignedCertificate.java:88)
at io.netty.handler.ssl.util.SelfSignedCertificate.(SelfSignedCertificate.java:79)
at nia.chapter12.SecureChatServer.main(SecureChatServer.java:36)

netty version

hello boss ,I read 《netty in action》 .I have a issue:in book code demo use netty version who number.

Chapter 5 directory structure does not match Java conventions

The source files for chapter5 contain the package declaration "package nia.chapter5;". Maven and the Java compiler expect to find the sources on the path "chapter5/src/main/java/nia/chapter5". Unfortunately, the path on Github is "chapter5/src/main/java/nia.chapter5". I don't know about other IDEs, but the Maven plugin for eclipse is very unhappy with that.

Unable to build examples in 2.0-SNAPSHOT branch

When running 'mvn clean package' in any of the example code directories of the SNAPSHOT 2.0 build I encounter the same maven dependency error "Failed to resolve artifact. Missing: nia:utils:jar:2.0-SNAPSHOT".

This is using an unmodified 2.0 branch checked out from github using IntelliJ14.

capture.txt

Can't start SPDY server

$ mvn clean package exec:exec -Pchapter12-SpdyServer
[INFO] --- exec-maven-plugin:1.2.1:exec (default-cli) @ netty-in-action ---
Exception in thread "main" java.lang.NoSuchMethodError: sun.security.ssl.SSLContextImpl.getSuportedCipherSuiteList()Lsun/security/ssl/CipherSuiteList;
    at sun.security.ssl.SSLEngineImpl.getSupportedCipherSuites(SSLEngineImpl.java:1982)
    at io.netty.handler.ssl.JdkSslContext.(JdkSslContext.java:101)
    at io.netty.handler.ssl.SslContext.newServerContext(SslContext.java:359)
    at io.netty.handler.ssl.SslContext.newServerContext(SslContext.java:311)
    at io.netty.handler.ssl.SslContext.newServerContext(SslContext.java:217)
    at io.netty.handler.ssl.SslContext.newServerContext(SslContext.java:131)
    at io.netty.handler.ssl.SslContext.newServerContext(SslContext.java:117)
    at com.manning.nettyinaction.chapter12.SpdyServer.main(SpdyServer.java:52)

with:

$ mvn -version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T13:58:10-07:00)
Maven home: /opt/java/apache-maven-3.2.3
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: /opt/java/jdk1.7.0_71/jre
Default locale: en_CA, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-37-generic", arch: "amd64", family: "unix"

Build of latest master fails

With:

$ mvn -version
Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T13:58:10-07:00)
Maven home: /opt/java/apache-maven-3.2.3
Java version: 1.7.0_71, vendor: Oracle Corporation
Java home: /opt/java/jdk1.7.0_71/jre
Default locale: en_CA, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-37-generic", arch: "amd64", family: "unix"

I get:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.manning.nettyinaction.chapter14.MemcachedRequestEncoderTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.221 sec
Running com.manning.nettyinaction.chapter14.MemcachedResponseDecoderTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
Running com.manning.nettyinaction.chapter10.AbsIntegerEncoderTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.006 sec <<< FAILURE!
testEncoded(com.manning.nettyinaction.chapter10.AbsIntegerEncoderTest)  Time elapsed: 0.006 sec  <<< ERROR!
io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
    at io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:101)
    at com.manning.nettyinaction.chapter10.AbsIntegerEncoderTest.testEncoded(AbsIntegerEncoderTest.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Running com.manning.nettyinaction.chapter10.FixedLengthFrameDecoderTest
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
Running com.manning.nettyinaction.chapter10.FrameChunkDecoderTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec

Results :

Tests in error: 
  testEncoded(com.manning.nettyinaction.chapter10.AbsIntegerEncoderTest): refCnt: 0, decrement: 1

Tests run: 7, Failures: 0, Errors: 1, Skipped: 0

8.4 Bootstrapping clients from a Channel

I am looking into bootstapping a client from a servers channel handler.
If I have Server1

  • serverhandler1
  • serverhandler2
  • Bootstrap a client1 connected to Server2
    • ClientHandler1
    • ClientHandler2
  • ServerHandler3

I am finding it difficult to understand how the data would flow in a setup like this.
Inbound from client that is connected to my server1.
Process the data and send it to the server2 connected by my client1.
Get a response from server2.
Do something with the response from server2 create a response and send it to the client connected to server1.
If its possible, could you provide some snippets or pointers on how to deal with this?
Did not find the book code provided in chap8 here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.