NEZ-762 增加对target格式为IP:PORT的情况的处理
This commit is contained in:
@@ -11,10 +11,17 @@ public class UdpUtils {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(TextFormatUtils.class);
|
||||
|
||||
public static String send(String sendIp,Integer slot,int timeout) {
|
||||
public static String send(String target,Integer slot,int timeout) {
|
||||
String sendIp = target;
|
||||
int port = 6800;
|
||||
String rlt = "";
|
||||
DatagramSocket ds = null;
|
||||
try {
|
||||
if(target.contains(":")) {
|
||||
int splitIndex = target.indexOf(":");
|
||||
sendIp = target.substring(0, splitIndex);
|
||||
port = Integer.parseInt(target.substring(splitIndex+1, target.length()));
|
||||
}
|
||||
ds = new DatagramSocket();//通过DatagramSocket对象创建udp服务
|
||||
ds.setSoTimeout(timeout);
|
||||
// String line = "00 06 0502 00 00 68c2"; //发送的16进制字符串
|
||||
@@ -24,7 +31,7 @@ public class UdpUtils {
|
||||
}
|
||||
String line = "00 "+slotStr+" 0502 00 00"; //发送的16进制字符串
|
||||
byte[] buf = HexUtils.hexStringToByteArray(line);
|
||||
DatagramPacket dp = new DatagramPacket(buf,buf.length,InetAddress.getByName(sendIp),6800);//发送至指定IP,指定端口
|
||||
DatagramPacket dp = new DatagramPacket(buf,buf.length,InetAddress.getByName(sendIp),port);//发送至指定IP,指定端口
|
||||
ds.send(dp);//通过send方法将数据包发送出去
|
||||
//定义数据包,用于存储数据
|
||||
byte[] buf2 = new byte[8];
|
||||
|
||||
Reference in New Issue
Block a user