https://github.com/wanxianliang/nettywebsocketserver
websocket server framwork base on netty
https://github.com/wanxianliang/nettywebsocketserver
netty netty4 websocket websocket-java websocket-server
Last synced: 4 months ago
JSON representation
websocket server framwork base on netty
- Host: GitHub
- URL: https://github.com/wanxianliang/nettywebsocketserver
- Owner: wanxianliang
- Created: 2021-09-07T12:52:25.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T12:52:50.000Z (over 2 years ago)
- Last Synced: 2025-01-13T02:24:46.521Z (5 months ago)
- Topics: netty, netty4, websocket, websocket-java, websocket-server
- Language: Java
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
This Repository is a web socket server base on Netty 。
Run a websocket server easily
```java
ServerRemote serverRemote = ServerRemote.newServerInstance(2222, requestPlus -> {
if (RequestTypeEnum.TEXT.getType().equals(requestPlus.getType())) {
RequestWithTextData requestWithTextData = (RequestWithTextData) requestPlus;
String text = requestWithTextData.getText();
log.info("server receive text data {}", text);
} else if (RequestTypeEnum.Binary.getType().equals(requestPlus.getType())) {
RequestWithBinaryData requestWithFileData = (RequestWithBinaryData) requestPlus;
ByteBuf buf = requestWithFileData.getByteBuf();
log.info("server receive binary data,buf size {}", buf.capacity());
}
return null;
});
serverRemote.run();
```Run Server in spring boot project
```java
public class SpringBootStartEvent implements ApplicationListener, ApplicationContextAware {
private ApplicationContext applicationContext;@Bean(name = "serverRemote")
ServerRemote createNettyRemote() {
return ServerRemote.newServerInstance(2222, requestPlus -> {
//deal with request and return response
});
}@Override
public void onApplicationEvent(SpringApplicationEvent springApplicationEvent) {
Object bean = applicationContext.getBean("serverRemote");
if (bean instanceof ServerRemote) {
try {
((ServerRemote) bean).run();
} catch (Exception e) {
e.printStackTrace();
}
log.info("Start netty server successfully");
}
}@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
```If you like this repo,please give me a start ❤️,thank you ❀