This is a learning experince - Getting to know DotNetty with .Net Core.
DotNetty is a port of Netty, asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients.
- Docs - The docs are for Netty (the Java version) and requires only small changes to apply to DotNetty
- Terminology
- http://netty.io/wiki/user-guide-for-4.x.html
- http://shengwangi.blogspot.com/2016/03/netty-tutorial-hello-world-example.html
- http://seeallhearall.blogspot.com/2012/06/netty-tutorial-part-15-on-channel.html
- Netty in Action book
Yes, used by Akka.Net, Azure IoT Hub and the IoT Hub Edge Runtime. Microsoft has tested it with 100,000 connections. Lots of big companies are using Netty.
Besides the official DotNetty examples this repo contains a couple of enhanced examples exploring features not covered by the official repo.
- Encode and decode byte[] into strings via the build-in StringEncoder and StringDecoder
- Chaining ChannelHandlers into a ChannelPipeline
- HelloWorldServerHandler implements SimpleChannelInboundHandler, which encapsulated DotNetty specific stuff like reference counting
- HasUpperCharsServerHandler implements raw ChannelHandlerAdapter and usages message forwarding to next Handler in the ChannelPipeline via FireChannelRead
- CountCharsServerHandler uses ChannelReadComplete to write to the output stream
Shows how to transform data into C# objects and back
- Encode and decode byte[] into POCO (Plain Old C# Objects) via the custom PersonEncoder and PersonDecoder
- PersonServerHandler implements SimpleChannelInboundHandler and works with Person objects
- Using multiple output encoders - one for Person objects and one for strings
Using multiple protocols at the same endpoint/port
- Two object types (StringObj and NumberObj) each decoded differently
- The first char is used as the protocol selector
- A = StringObj
- B = NumberObj
- The first char is used as the protocol selector
- There are multiple ways of handling multiple protocols
- The initial message sets the protocol - see InitialProtocolSelectorDecoder
- Every message forward the protocol selector char - See ProtocolSelectorDecoder
- The channel pipeline is modified dynamically via one of the to ProtocolSelectorDecoders, so the pipeline in Program.cs does not have a full functional pipeline.
- This sample also shows how to use the IdleStateHandler fireing UserEvents, catched by TerminateIdleConnectionHandler