Skip to content

Lybecker/DotNettyPlayground

Repository files navigation

DotNetty Playground

This is a learning experince - Getting to know DotNetty with .Net Core.

Build status

DotNetty

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

Great tutorials & blogs

Is it production ready?

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.

This repository - Coding Examples

Besides the official DotNetty examples this repo contains a couple of enhanced examples exploring features not covered by the official repo.

Hello World

  • 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

POCO (Plain Old C# Objects)

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

Multiple Protocols

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
  • 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

Releases

No releases published

Packages

No packages published

Languages