AsyncNetwork short for AsynchronousNetwork is a library which implements an easy-to-use, fast, TCP network
- Cross platform (Windows, Linux, Mac, Android etc...)
- Asynchronous
- Can handle lots of clients at once
- Easy-to-use
- Fast and efficient
<dependency>
<groupId>com.github.oughttoprevail</groupId>
<artifactId>AsyncNetwork</artifactId>
<version>1.3.1</version>
</dependency>
Here is The Central Repository.
To create a client you would do:
ClientSocket client = new ClientSocket();
client.onConnect(() -> WritablePacketBuilder.create().putByte(Byte.MAX_VALUE).build().writeAndClose(client));
client.connectLocalHost(/*Specify your port here (0-65535) example: 6000*/6000);
To create a server you would do:
ReadablePacket packet = ReadablePacketBuilder.create().aByte().build();
ServerSocket server = new ServerSocket();
server.onConnection(client ->
{
client.always(true);
packet.read(client, readResult ->
{
byte value = readResult.poll();
System.out.println("value=" + value);
});
client.onDisconnect(disconnectionType -> System.out.println("Disconnected" + disconnectionType));
});
server.bindLocalHost(6000);
while(true);
And you're finished! now you can use AsyncNetwork for your networking projects. Good luck!
Windows uses IO completion ports for best asynchronous performance.
Linux has sys/epoll which is famous for it's O(1) epoll_wait
performance.
Mac has FreeBSD features including kqueue which is also O(1).
Other operating systems are not supported by different native implementations, so AsyncNetwork uses the already implemented java.nio.channels.Selector.
Special thanks to Jacob and despair who helped me make this!