package com.xcong.excoin.netty.logic;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.xcong.excoin.netty.bean.RequestBean;
|
import com.xcong.excoin.netty.bean.ResponseBean;
|
import com.xcong.excoin.netty.common.ChannelManager;
|
import com.xcong.excoin.netty.common.NettyTools;
|
import io.netty.channel.Channel;
|
import org.springframework.stereotype.Component;
|
|
|
/**
|
* @author wzy
|
* @email wangdoubleone@gmail.com
|
* @date 2019-05-09
|
*/
|
@Component
|
public class WebSocketLogic {
|
|
|
public void webReqConnection(RequestBean requestBean) {
|
Channel channel = ChannelManager.findWebSocketChannel(requestBean.getChannelId());
|
channel.writeAndFlush(NettyTools.webSocketBytes("this is ok"));
|
}
|
|
public void reqHomeSymbols(RequestBean requestBean) {
|
String params = requestBean.getParams();
|
JSONObject jsonObject = JSONObject.parseObject(params);
|
String token = jsonObject.getString("token");
|
String type = jsonObject.getString("type");
|
ResponseBean responseBean = ResponseBean.ok(requestBean.getType(), null);
|
|
Channel channel = ChannelManager.findWebSocketChannel(requestBean.getChannelId());
|
channel.writeAndFlush(NettyTools.webSocketBytes(JSONObject.toJSONString(responseBean)));
|
}
|
|
public void defaultReq(RequestBean requestBean) {
|
Channel channel = ChannelManager.findWebSocketChannel(requestBean.getChannelId());
|
channel.writeAndFlush("this is error type");
|
}
|
}
|