| File | Date | Author | Commit |
|---|---|---|---|
| .github | 2021-06-24 |
|
[333bae] Create FUNDING.yml |
| src | 2021-06-30 |
|
[8558a7] 修复细节 |
| .gitignore | 2021-04-10 |
|
[31b4d7] 首次提交 |
| BACKERS.md | 2021-06-25 |
|
[727653] 添加支持者榜单 |
| LICENSE | 2021-04-12 |
|
[15e460] 首次提交 |
| README.md | 2021-06-30 |
|
[77d964] 修复细节 |
| pom.xml | 2021-06-30 |
|
[3add28] 修复细节 |
Magician is an asynchronous non-blocking network protocol analysis package, supports TCP, UDP protocol, built-in Http, WebSocket decoder
JDK11+
If you want to use it on a lower version of the JDK, you can download the source code of this repository and compile it yourself.
<dependency>
<groupId>com.github.yuyenews</groupId>
<artifactId>Magician</artifactId>
<version>last version</version>
</dependency>
<!-- This is the log package, which supports any package that can be bridged with slf4j -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.12</version>
</dependency>
public class DemoHandler implements MagicianHandler<MagicianRequest> {
@Override
public void request(MagicianRequest magicianRequest) {
// response data
magicianRequest.getResponse()
.sendJson(200, "{'status':'ok'}");
}
}
Magician.createTCPServer()
.handler("/", new DemoHandler())
.bind(8080);
EventGroup ioEventGroup = new EventGroup(1, Executors.newCachedThreadPool());
EventGroup workerEventGroup = new EventGroup(10, Executors.newCachedThreadPool());
// When the current EventRunner has no tasks, it is allowed to steal tasks from other EventRunners
workerEventGroup.setSteal(EventEnum.STEAL.YES);
Magician.createTCPServer(ioEventGroup, workerEventGroup)
.handler("/", new DemoHandler())
.bind(8080);
// Listen to n ports, write n as the first parameter of ioEventGroup
EventGroup ioEventGroup = new EventGroup(2, Executors.newCachedThreadPool());
EventGroup workerEventGroup = new EventGroup(10, Executors.newCachedThreadPool());
// When the current EventRunner has no tasks, it is allowed to steal tasks from other EventRunners
workerEventGroup.setSteal(EventEnum.STEAL.YES);
TCPServer tcpServer = Magician
.createTCPServer(ioEventGroup, workerEventGroup)
.handler("/", new DemoHandler())
tcpServer.bind(8080);
tcpServer.bind(8088);
Just add a handler when creating the http service
Magician.createTCPServer()
.handler("/", new DemoHandler())
.webSocketHandler("/websocket", new DemoSocketHandler())
.bind(8080);
Magician.createUdpServer()
.handler(outputStream -> {
// outputStream is of type ByteArrayOutputStream
// It is the data sent by the client, you can parse it by yourself
}).bind(8088);
In addition to this way of writing, you can also create a separate handler, add here