https://github.com/paganini2008/embedded-io
A lightweight, high-performance, and extensible TCP/IP networking framework designed for Java developers building scalable and robust network applications. It features an event-driven, non-blocking architecture that simplifies the creation of custom communication protocols and real-time systems.
https://github.com/paganini2008/embedded-io
java nio-library socket-io tcp-ip
Last synced: 15 days ago
JSON representation
A lightweight, high-performance, and extensible TCP/IP networking framework designed for Java developers building scalable and robust network applications. It features an event-driven, non-blocking architecture that simplifies the creation of custom communication protocols and real-time systems.
- Host: GitHub
- URL: https://github.com/paganini2008/embedded-io
- Owner: paganini2008
- Created: 2021-02-02T10:24:40.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-07-09T05:02:05.000Z (almost 4 years ago)
- Last Synced: 2025-12-05T00:22:07.805Z (7 months ago)
- Topics: java, nio-library, socket-io, tcp-ip
- Language: Java
- Homepage: https://github.com/paganini2008/embedded-io
- Size: 90.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# embedded-io
A lightweight NIO framework with JDK8
## Compatibility
* Jdk 1.8 (or later)
## Install
```xml
com.github.paganini2008
embedded-io
2.0.4
```
## Quick Start
**Example 1**
Start Nio Server
``` java
public static void main(String[] args) throws Exception {
NioAcceptor server = new NioAcceptor();
server.getTransformer().setSerialization(new StringSerialization(), new ObjectSerialization());
server.setReaderBufferSize(10 * 1024);
LoggingChannelHandler handler = new LoggingChannelHandler("server");
server.addHandler(handler);
server.start();
System.in.read();
server.stop();
}
```
Start Nio Client
``` java
public static void main(String[] args) throws Exception {
NioConnector client = new NioConnector();
client.getTransformer().setSerialization(new ObjectSerialization(), new StringSerialization());
client.setWriterBufferSize(20 * 1024);
client.setWriterBatchSize(10);
client.setAutoFlushInterval(3);
ChannelHandler handler = new LoggingChannelHandler("client");
client.addHandler(handler);
Channel channel;
try {
channel = client.connect(new InetSocketAddress(8090), new ChannelPromise() {
@Override
public void onSuccess(Channel channel) {
System.out.println(channel + " is ok");
}
@Override
public void onFailure(Throwable e) {
e.printStackTrace();
}
});
} catch (Exception e) {
e.printStackTrace();
throw e;
}
System.in.read();
for (int i = 0; i < 10000; i++) {
channel.write(new Item("test_" + i, UUID.randomUUID().toString()));
}
Thread.sleep(60 * 1000L);
client.close();
}
```
**Example 2**
Start Aio Server
``` java
public static void main(String[] args) throws Exception {
AioAcceptor server = new AioAcceptor();
server.getTransformer().setSerialization(new StringSerialization(), new ObjectSerialization());
server.setReaderBufferSize(10 * 1024);
LoggingChannelHandler handler = new LoggingChannelHandler("server");
server.addHandler(IdleChannelHandler.readerIdle(60, 60, TimeUnit.SECONDS, IdleTimeoutListener.LOG));
server.addHandler(handler);
server.start();
System.in.read();
server.stop();
}
```
Start Client
``` java
public static void main(String[] args) throws Exception {
AioConnector client = new AioConnector();
client.getTransformer().setSerialization(new ObjectSerialization(), new StringSerialization());
// client.setWriterBufferSize(20 * 1024);
client.addHandler(IdleChannelHandler.writerIdle(30, 60, TimeUnit.SECONDS, IdleTimeoutListener.LOG));
client.setWriterBatchSize(10);
client.setAutoFlushInterval(3);
ChannelHandler handler = new LoggingChannelHandler("client");
client.addHandler(handler);
Channel channel;
try {
channel = client.connect(new InetSocketAddress("127.0.0.1", 8090), new ChannelPromise() {
@Override
public void onSuccess(Channel channel) {
System.out.println(channel + " is ok");
}
@Override
public void onFailure(Throwable e) {
e.printStackTrace();
}
});
} catch (Exception e) {
e.printStackTrace();
throw e;
}
System.in.read();
for (int i = 0; i < 10000; i++) {
channel.write(new Item("test_" + i, UUID.randomUUID().toString()));
}
Thread.sleep(60 * 1000L);
client.close();
}
```