Coder Social home page Coder Social logo

d3adspace / skylla Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 2.0 289 KB

Powerful and robust packet event driven network framework built on top of netty and nio that offers rapid custom binary protocol development.

Home Page: https://www.d3adspace.de

License: MIT License

Java 100.00%
packet-events async netty powerful simple backend embedded sasuke sasukekawaii

skylla's Introduction

skylla

A simple network framework based on packet events. First taken as a PROC we decided to publish this and develop some more features in the future in order to provider a lightweight but powerful framework for little network applications that want to outsource their network handling parts.

Skylla uses constrictor networking utils.

Installation / Usage

Build from Source

  • Install Maven
  • Clone this repo
  • Instal: mvn clean install

Maven Repository

Maven dependencies

Repositories:

<repositories>
  <!-- Klauke Enterprises Releases -->
  <repository>
    <id>klauke-enterprises-maven-releases</id>
    <name>Klauke Enterprises Maven Releases</name>
    <url>https://repository.klauke-enterprises.com/repository/maven-releases/</url>
  </repository>
</repositories>

Dependencies:

<dependency>
  <groupId>de.d3adspace.skylla</groupId>
  <artifactId>skylla-client</artifactId>
  <version>4.0.0</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>de.d3adspace.skylla</groupId>
  <artifactId>skylla-server</artifactId>
  <version>4.0.0</version>
  <scope>compile</scope>
</dependency>

Example

Server and Client instantiation

public class ServerExample {
  public static void main(String[] args) {
    
    // The shared protocol
    Protocol protocol = Protocol.newBuilder()
      .withPacket(ChatPacket.class)
      .build();
    
    
    // Server
    ExampleServerListener exampleServerListener = ExampleServerListener.create();
    SkyllaServer server = NettySkyllaServer.newBuilder()
      .withServerHost("localhost")
      .withServerPort(8080)
      .withProtocol(protocol)
      .withListener(exampleServerListener)
      .build();

    server.start();

    // Client
    ExampleClientListener exampleClientListener = ExampleClientListener.create();
    SkyllaClient client = NettySkyllaClient.newBuilder()
      .withServerHost("localhost")
      .withServerPort(8080)
      .withProtocol(protocol)
      .withListener(exampleClientListener)
      .build();

    client.connect();
      
    ChatPacket chatPacket = ChatPacket.of("Client", "Hey Server!");
    client.sendPacket(chatPacket);
  }
  
  public static final class ExampleClientListener {
    private static final FluentLogger logger = FluentLogger.forEnclosingClass();
  
    private ExampleClientListener() {
    }

    private ExampleClientListener create() {
      return new ExampleClientListener();
    }   

    @PacketListener
    public void onChatPacket(PacketContext packetContext, ChatPacket chatPacket) {
      logger.atInfo().log("%s: %s", chatPacket.getName(), chatPacket.getMessage());
    }
  }

  public static final class ExampleServerListener {
    private static final FluentLogger logger = FluentLogger.forEnclosingClass();
  
    private ExampleServerListener() {
    }

    private ExampleServerListener create() {
      return new ExampleServerListener();
    }   

    @PacketListener
    public void onChatPacket(PacketContext packetContext, ChatPacket chatPacket) {
      ChatPacket answer = ChatPacket.of("Server", "Hey Client!");
      packetContext.resume(answer);
    }
  }
}

Packet definition

@PacketMeta(id = 1)
public final class ChatPacket implements Packet {
  private String name;
  private String message;

  public ChatPacket() {
  }

  private ChatPacket(String name, String message) {
    this.name = name;
    this.message = message;
  }

  public static ChatPacket of(String name, String message) {
    Preconditions.checkNotNull(name);
    Preconditions.checkNotNull(message);

    return new ChatPacket(name, message);
  }

  @Override
  public void read(SkyllaBuffer buffer) {
    name = buffer.readString();
    message = buffer.readString();
  }

  @Override
  public void write(SkyllaBuffer buffer) {
    buffer.writeString(name);
    buffer.writeString(message);
  }

  public String getMessage() {
    return message;
  }

  public String getName() {
    return name;
  }
}

skylla's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar felixklauke avatar jeromewolff avatar larsartmann avatar nathalie0hneherz avatar rubyhale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

skylla's Issues

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.