https://github.com/trigary/simplenetty
A simple, asynchronous, event driven and highly performant Netty wrapper.
https://github.com/trigary/simplenetty
api java library netty networking packet packets simple simple-api
Last synced: 9 months ago
JSON representation
A simple, asynchronous, event driven and highly performant Netty wrapper.
- Host: GitHub
- URL: https://github.com/trigary/simplenetty
- Owner: Trigary
- License: mit
- Created: 2018-06-26T18:01:52.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-02-06T13:16:30.000Z (almost 5 years ago)
- Last Synced: 2025-04-12T10:14:13.237Z (9 months ago)
- Topics: api, java, library, netty, networking, packet, packets, simple, simple-api
- Language: Java
- Size: 17.6 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleNetty [](https://jitpack.io/#Trigary/SimpleNetty)
A wrapper around the Netty framework, which makes it easy to use
while maintaining its most powerful aspects:
it is asynchronous, event driven and highly performant.
## Main differences
There are three main features this wrapper adds to Netty:
- Straight forward server/client initialization and
binding/connecting
- An extendable class instance is bound to each connected client
allowing easy state management (eg. login checks)
- Provide the base class of all transmitted data and a
serializer, deserializer for it and worry about
bytes, serialization no more
## Switching to / from Netty
Switching between plain Netty and this wrapper is extremely easy.
The same thread model is used, there is no need to redo the event
listeners. There is always a simple way in this wrapper to access
Netty directly, giving you the same freedom as Netty provides.
## Documentation
- [JavaDocs](http://trigary.hu/javadocs/simple-netty/)
- [Server reference](server.md)
- [Client reference](client.md)
## Importing
You can add SimpleNetty as a dependency as follows:
```xml
jitpack.io
https://jitpack.io
com.github.Trigary
SimpleNetty
1.0
```
Please note that Netty is not shaded into SimpleNetty,
you have to add it yourself.
## Example
You can check out the SimpleNettyExample folder for a
minimalistic, but complete chat client-server implementation.
The following tiny code snippet aims to show you what it's like
to be using SimpleNetty. It's a simple text ECHO server.
```java
//A serializer, deserializer for the type of the transmitted data: String
DataSerializer stringSerializer = new DataSerializer() {
@Override
public byte[] serialize(String data) {
return data.getBytes(StandardCharsets.US_ASCII);
}
@Override
public String deserialize(byte[] bytes) {
return new String(bytes, StandardCharsets.US_ASCII);
}
@Override
public Class getType() {
return String.class;
}
};
//Instantiate and initialize a new Server.
//ServerClient is the class which is bound to all connected clients.
Server, String> server = new Server<>(stringSerializer, ServerClient::new);
server.onReceived((client, data) -> client.send(data));
//Bind the server to no specified address, but to the port 800.
server.start(null, 800);
//Instantiate and initialize a new Client.
Client client = new Client<>(stringSerializer);
client.onConnected(() -> client.send("Hello Server!"));
client.onReceived(System.out::println);
//Connect to the localhost address on the port 800 without any timeout.
client.connect("localhost", 800, 0);
```
##
This project was inspired by
[SimpleNet](https://github.com/jhg023/SimpleNet/),
ty [Jacob](https://github.com/jhg023)