package com.fzzy.protocol.fzzy.cmd;
|
|
|
import com.fzzy.api.data.GatewayDeviceProtocol;
|
import com.fzzy.api.utils.ContextUtil;
|
import com.fzzy.protocol.fzzy.data.SendMessage;
|
import com.fzzy.protocol.fzzy.server.FzzyServerEngine;
|
import com.ld.io.api.InvokeResult;
|
import com.ld.io.api.IoSession;
|
import com.ld.io.api.IoSessionQuery;
|
import lombok.extern.slf4j.Slf4j;
|
|
import java.util.List;
|
|
@Slf4j
|
public class BaseRemoteImpl {
|
|
/**
|
* 发送命令
|
*
|
* @param ip
|
* @param port
|
* @param msg
|
* @return
|
*/
|
public InvokeResult send(String ip, int port, byte[] msg) {
|
IoSessionQuery sessionFactory = FzzyServerEngine.ioServer.getSessionQuery();
|
List<IoSession> sessions = sessionFactory.getAllSession();
|
IoSession session = null;
|
for (IoSession ioSession : sessions) {
|
if (ContextUtil.getServerKey(ip, port).equals(
|
ioSession.getBusinessKey())) {
|
session = ioSession;
|
break;
|
}
|
}
|
if (null == session) {
|
return InvokeResult.CHANNEL_CLOSED;
|
}
|
return session.invoke(msg);
|
}
|
|
public InvokeResult send(SendMessage message) {
|
// log.debug("平台发送报文---->>控制柜--{}", message.toString());
|
IoSessionQuery sessionFactory = FzzyServerEngine.ioServer.getSessionQuery();
|
List<IoSession> sessions = sessionFactory.getAllSession();
|
IoSession session = null;
|
for (IoSession ioSession : sessions) {
|
if (ContextUtil.getServerKey(message.getIp(), message.getPort()).equals(
|
ioSession.getBusinessKey())) {
|
session = ioSession;
|
break;
|
}
|
}
|
if (null == session) {
|
return InvokeResult.CHANNEL_CLOSED;
|
}
|
return session.invoke(message.getByteMsg());
|
}
|
|
}
|