Native asynchronous network library with packet-based architecture
Yes, I really know that there are other network libraries (Netty, for example), but I needed my own version of an asynchronous library with its own built-in exchange protocol and with a packet abstraction layer, but at the same time with support for sending raw data. And so that all this was simple. Well, in general, I just want to invent the wheel :)
Current (08.2021) network library state is unstable and low tested, so be careful, library will be updated and verified over time
In general, I advise you to look at the examples in the tests section, it is simple. But here is some basics:
- Create network parameters (
NetworkParameters
) instance; - Setup network parameters if you want (handshake sending, authorization, encrypt, compress etc.) or default will be applied;
- Create your custom packets
implements Packet
and register it in your packet registrator classimplements PacketRegistrator
; - Create your server listener
implements NetworkServerListener
, which will be accept many events, such asonHandshake
oronPacketReceive
and others; - Create server (
KudesuNetworkServer server = KudesuNetwork.createServer(port, packetRegistrator, networkListener, networkParameters)
) - Launch server
server.start()
; - Create your client listener
implements NetworkClientListener
, which will be accept many events, such asonHandshake
oronPacketReceive
and others; - You can create both separate from server parameters class and packet registrator class, either reuse already created classes;
- Create client (
KudesuNetworkClient client = KudesuNetwork.createClient(address, port, packetRegistrator, networkListener, networkParameters)
); - Lauch client
client.connect()
; - Send your client packets by calling
sendPacket(new <? extends Packet> yourPacket)
method; - Send your server packets by calling
sendPacket(port, new <? extends Packet> yourPacket)
orsendBroadcast(new <? extends Packet> yourPacket)
methods; - Handle packet recieving in your classes
implements NetworkClientListener
andimplements NetworkServerListener
; - Enjoy!
- You may disconnect client by calling
client.disconnect(reason)
orclient.disconnect()
; - You !MUST! stop server by calling
server.stop()
or server will listen to port endlessly;
Protocols list and details
- TCP (using by Raw, Kudesu, HTTP / HTTPS, WebSocket)
- UDP (using by Raw, Kudesu)
- Raw (no protocol) (client, server)
- Kudesu (custom protocol) (client, server)
- HTTP / HTTPS (client, server)
- WebSocket (client, server)
This is Gradle projects
When you're ready to submit your code, just make a pull request.
- Start by searching issue tracker for duplicates;
- Create a new issue, explaining the problem in proper detail.
MIT License. See LICENSE file for details.