| | |
| | | import io.netty.channel.group.DefaultChannelGroup; |
| | | import io.netty.util.CharsetUtil; |
| | | import io.netty.util.concurrent.GlobalEventExecutor; |
| | | import org.springblade.modules.alarm.service.IAlarmService; |
| | | import org.springblade.modules.alarm.vo.AlarmVO; |
| | | import org.springblade.modules.catalog.service.catalogService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class ServerHandler extends ChannelInboundHandlerAdapter { |
| | | |
| | | @Autowired |
| | | private catalogService catalogService; |
| | | |
| | | private static ServerHandler serverHandler; |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | serverHandler = this; |
| | | } |
| | | /** |
| | | * 客户端与服务端创建连接的时候调用 |
| | | */ |
| | |
| | | String body = new String(req, "UTF-8"); |
| | | System.out.println("接收客户端数据:" + body); |
| | | channelHandlerContext.writeAndFlush(Unpooled.copiedBuffer("LEOK#@!", CharsetUtil.UTF_8)); |
| | | List<Map<String, Object>> list = serverHandler.catalogService.selectCatalogList(); |
| | | System.out.println(list); |
| | | // ByteBuf pingMessage = Unpooled.buffer(); |
| | | // pingMessage.writeBytes(req); |
| | | // channelHandlerContext.writeAndFlush(pingMessage); |