Giter VIP home page Giter VIP logo

netty-kit's Introduction

Netty Kit 🛩ī¸

With the NettyKit it is easy to create a NettyServer and a NettyClient. It is important to note that this project requires the client server API.

Using the Netty Kit in your plugin

Maven

<dependencies>
 <dependency>
    <groupId>world.avionik</groupId>
    <artifactId>netty-kit</artifactId>
    <version>1.0.1</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

Gradle

dependencies {
    compileOnly 'world.avionik:netty-kit:1.0.1'
}

How to create a Netty Server

You can use these methods to create a new NettyServer. There are two ways to specify the host and port. Once in a config or as a system environment variable

NettyServerConfigurator(NettyServerSettings.fromConfig())  // Here you can also use fromEnv() here
    .withPackets(PacketOutTesting::class.java, PacketInSomeCoolThings::class.java)
    .start()

Now you have the NettyServerHandler. You can then use this handler to send packets to the clients. Here is a small example:

val nettyServerHandler = NettyServerConfigurator(NettyServerSettings.fromConfig())
    .withPackets(PacketOutTesting::class.java, PacketInSomeCoolThings::class.java)
    .start()

val packet = PacketOutTesting()

nettyServerHandler.sendPacket(packet, "netty-client") // Here you get a CommunicationPromise as a return type
    .addResultListener { println("success") }
    .addFailureListener { println("failed") }

// And this is how you send a packet to all connected Netty clients
nettyServerHandler.sendPacketToAllClients(packet)

How to create a Netty Client

If you have already created the NettyServer, you now need the client. Here is how to create a Netty client:

// And here, too, there are two options for the host and port settings.
NettyClientConfigurator(NettyClientSettings.fromConfig("netty-client.yaml"), "ClientName") // This is the name of the Netty client
    .withPackets(PacketInTesting::class.java, PacketOutSomeCoolThings::class.java)
    .withAutoReconnect() // This allows you to set the client to automatically reconnect in the event of a netty server shutdown
    .start()

Here you have the option of sending a packet to the Netty server with the NettyClientHandler:

val nettyClientHandler = NettyClientConfigurator(NettyClientSettings.fromConfig("netty-client.yaml"), "ClientName")
    .withPackets(PacketInTesting::class.java, PacketOutSomeCoolThings::class.java)
    .withAutoReconnect()
    .start()

val packet = PacketOutSomeCoolThings()
nettyClientHandler.sendPacketToServer(packet)
    .addResultListener { println("success") }
    .addFailureListener { println("failed") }

netty-kit's People

Contributors

niklasnieberler avatar

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.