- 浏览: 191707 次
- 性别:
- 来自: 深圳
最新评论
-
shis_y:
那是你的localhost或者web服务器的80端口被占用或者 ...
通过虚拟地址解决fckeditor错误的加载/fckeditor/fckstyles.xml -
forcer521:
com.gemt.dataswap.util.Constant ...
使用DES算法进行加密和解密 -
ngn9999:
dTree确实不错,这是我的使用经验: http://www. ...
javascript树型菜单(Dtree和Xtree) -
yueliangwolf:
这个dhtmlxtree.js里面有enableSmartXM ...
使用xml或者json方式生成dhtmlxtree -
yanMouse:
谢谢,能否有个联系方式,我现在也在看这方面的东西
dhtmlxtree的一个实用demo
花了几天时间整了一下,暂时还没有完工,不过先把源码上传一下,与大家分享一下。
服务端:
public class SpringMain {
public static void main(String[] args) throws Exception {
if (System.getProperty("com.sun.management.jmxremote") != null) {
System.out.println("JMX enabled.");
} else {
System.out
.println("JMX disabled. Please set the "
+ "'com.sun.management.jmxremote' system property to enable JMX.");
}
getApplicationContext();
System.out.println("Listening ...");
}
public static ConfigurableApplicationContext getApplicationContext() {
return new ClassPathXmlApplicationContext("com/gomt/slop/monitor/serverContext.xml");
}
}
客户端一共有三种:swing(NIO非阻塞),applet(old IO,用以前的阻塞IO),还有一种就是C#的客户端(暂不提供代码)。
Applet客户端:
package com.gomt.slop.monitor.client;
import com.gomt.slop.monitor.CRC16;
import com.gomt.slop.monitor.ChatCommand;
import com.gomt.slop.monitor.ChatProtocol;
import com.gomt.slop.monitor.Util;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class OtherChatClient extends Applet {
private static final long serialVersionUID = -1998630511274235821L;
protected boolean loggedIn = false;// 登入状态
protected Frame cp;// 聊天室框架
protected static int PORTNUM = 1234;//7777; // 缺省端口号7777
protected int port;// 实际端口号
protected Socket sock;
protected BufferedReader is;// 用于从sock读取数据的BufferedReader
protected PrintWriter pw;// 用于向sock写入数据的PrintWriter
protected TextField tf;// 用于输入的TextField
protected Choice userList; //用于显示在线的用户列表
protected TextArea ta;// 用于显示对话的TextArea
protected Button lib;// 登入按钮
protected Button lob;// 登出的按钮
final static String TITLE = "数据在线监测applet客户端";
protected String paintMessage;// 发表的消息
int i = 0;
final String name = "appletuser";
//public ChatParameter Chat;
enum CharParameter {
LOGIN,
BROADCAST,
QUIT
}
public void init() {
paintMessage = "正在生成聊天窗口";
repaint();
cp = new Frame(TITLE);
cp.setLayout(new BorderLayout());
String portNum = getParameter("port");
port = PORTNUM;
if (portNum != null) // 书上是portNum==null,十分有问题
port = Integer.parseInt(portNum);
// CGI
ta = new TextArea(14, 80);
ta.setEditable(false);// read only attribute
ta.setFont(new Font("Monospaced", Font.PLAIN, 11));
ta.setText("init()\r\n");
cp.add(BorderLayout.NORTH, ta);
Panel p = new Panel();
Button b;
// for login button
p.add(lib = new Button("登陆"));
lib.setEnabled(true);
lib.requestFocus();
lib.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
login();
lib.setEnabled(false);
lob.setEnabled(true);
tf.requestFocus();// 将键盘输入锁定再右边的文本框中
}
});
// for logout button
p.add(lob = new Button("退出"));
lob.setEnabled(false);
lob.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
logout();
lib.setEnabled(true);
lob.setEnabled(false);
lib.requestFocus();
}
});
userList = new Choice();
userList.add(" ");
userList.setSize(new Dimension(80, 10));
p.add(userList);
p.add(new Label("输入消息:"));
tf = new TextField(30);
tf.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (loggedIn) {
// int j = tf.getText().indexOf(":");
// if (j > 0)
// pw.println(CharParameter.BROADCAST + " " + tf.getText());
// else
// pw.println(CharParameter.BROADCAST + " " + tf.getText());
final String logonPacket = "QN="+Util.getQN()+ ";ST=32;CN=6003;Flag=3;PW=123456;CP=&&Msg=" + tf.getText() + "&&";
pw.println("##" + Util.formate4Bit(logonPacket.length()) + logonPacket + CRC16.getHex(logonPacket) + "");
tf.setText("");
}
}
});
p.add(tf);
cp.add(BorderLayout.SOUTH, p);
cp.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// 如果执行了setVisible或者dispose,关闭窗口
OtherChatClient.this.cp.setVisible(false);
OtherChatClient.this.cp.dispose();
logout();
}
});
cp.pack();
// 将Frame cp放在中间
Dimension us = cp.getSize(), them = Toolkit.getDefaultToolkit()
.getScreenSize();
int newX = (them.width - us.width) / 2;
int newY = (them.height - us.height) / 2;
cp.setLocation(newX, newY);
cp.setVisible(true);
paintMessage = "Window should now be visible";
repaint();
}
// 登录聊天室
public void login() {
if (loggedIn)
return;
try {
sock = new Socket(getCodeBase().getHost(), port);
is = new BufferedReader(
new InputStreamReader(sock.getInputStream()));
pw = new PrintWriter(sock.getOutputStream(), true);
} catch (IOException e) {
showStatus("Can't get socket: " + e);
cp.add(new Label("Can't get socket: " + e));
return;
}
// 假定登录(其实只是打印相关信息,并没有真正登录)
// pw.println(Chat.CMD_LOGIN+"AppletUser");
//pw.println(CharParameter.LOGIN + " " + "AppletUser");
final String logonPacket = "QN="+Util.getQN()+ ";ST=32;CN=6001;Flag=3;STCODE=" + name + ";PW=123456;CP=&&&&";
pw.println("##" + Util.formate4Bit(logonPacket.length()) + logonPacket + CRC16.getHex(logonPacket) + "");
loggedIn = true;
// 构造并且启动读入器,从服务器读取数据,输出到文本框中
// 这里使用一个线程来避免锁住资源(lockups)
new Thread(new Runnable() {
public void run() {
String line;
try {
while (loggedIn && ((line = is.readLine()) != null)) {
ta.append(line + "\n"); //.appendText(line + "\n");
String theMessage = (String) line;
ChatProtocol cp = new ChatProtocol(theMessage);
if(cp.isValidMessage()) {
System.out.println("合法的消息!");
int protocol = cp.getProtocol();
System.out.println("协议为:" + protocol + " QN = " + cp.getQN());
switch(protocol) {
case ChatCommand.USERLIST :
String users = cp.getCPONUsers();
if(users != null && !"".equals(users.trim())) {
String[] userArr = users.split("@");
userList.removeAll();
userList.add("全部");
for(String s : userArr) {
userList.add(s);
}
}
break;
}
}
}
} catch (IOException e) {
showStatus("我的天啊,掉线了也!!!!");
return;
}
}
}).start();
}
// 模仿退出的代码
public void logout() {
if (!loggedIn)
return;
loggedIn = false;
try {
if (sock != null) {
pw = new PrintWriter(sock.getOutputStream(), true);
//pw.println(CharParameter.QUIT + " " + "AppletUser");
final String logonPacket = "QN="+Util.getQN()+ ";ST=32;CN=6002;Flag=3;PW=123456;CP=&&&&";
pw.println("##" + Util.formate4Bit(logonPacket.length()) + logonPacket + CRC16.getHex(logonPacket) + "");
sock.close();
}
} catch (IOException ign) {
// 异常处理哦
}
}
// 没有设置stop的方法,即使从浏览器跳到另外一个网页的时候
// 聊天程序还可以继续运行
public void paint(Graphics g) {
Dimension d = getSize();
int h = d.height;
int w = d.width;
g.fillRect(0, 0, w, 2);
g.setColor(Color.black);
g.drawString(paintMessage, 10, (h / 2) - 5);
}
}
swing客户端:
package com.gomt.slop.monitor.client;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import com.gomt.slop.monitor.client.SwingChatClientHandler.Callback;
import javax.swing.JComboBox;
import javax.swing.JScrollPane;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
/**
* Simple chat client based on Swing & MINA that implements the chat protocol.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
*/
public class SwingChatClient extends JFrame implements Callback {
private static final long serialVersionUID = 1538675161745436968L;
private JTextField inputText;
private JButton loginButton;
private JButton quitButton;
private JButton closeButton;
private JTextField serverField;
private JTextField nameField;
private JTextArea area;
private JComboBox userList;
private JScrollBar scroll;
private ChatClientSupport client;
private SwingChatClientHandler handler;
private NioSocketConnector connector;
public SwingChatClient() {
super("环境监测swing客户端");
connector = new NioSocketConnector();
loginButton = new JButton(new LoginAction());
loginButton.setText("连接");
quitButton = new JButton(new LogoutAction());
quitButton.setText("断开");
closeButton = new JButton(new QuitAction());
closeButton.setText("退出");
inputText = new JTextField(30);
inputText.setAction(new BroadcastAction());
area = new JTextArea(10, 50);
area.setLineWrap(true);
area.setEditable(false);
area.setAutoscrolls(true);
// scroll = new JScrollBar();
// scroll.add(area);
// scroll.setSize(new Dimension(200, 100));
JScrollPane scrollPane = new JScrollPane(area);
nameField = new JTextField(10);
nameField.setEditable(false);
serverField = new JTextField(10);
serverField.setEditable(false);
JPanel h = new JPanel();
h.setLayout(new BoxLayout(h, BoxLayout.LINE_AXIS));
h.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JLabel nameLabel = new JLabel("用户名: ");
JLabel serverLabel = new JLabel("服务器: ");
h.add(nameLabel);
h.add(Box.createRigidArea(new Dimension(10, 0)));
h.add(nameField);
h.add(Box.createRigidArea(new Dimension(10, 0)));
h.add(Box.createHorizontalGlue());
h.add(Box.createRigidArea(new Dimension(10, 0)));
h.add(serverLabel);
h.add(Box.createRigidArea(new Dimension(10, 0)));
h.add(serverField);
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.LINE_AXIS));
p.setBorder(new EmptyBorder(10, 10, 10, 10));
JPanel left = new JPanel();
left.setLayout(new BoxLayout(left, BoxLayout.PAGE_AXIS));
left.add(scrollPane);
//left.add(area);
left.add(Box.createRigidArea(new Dimension(0, 5)));
left.add(inputText);
left.add(Box.createHorizontalGlue());
left.add(Box.createRigidArea(new Dimension(0, 25)));
userList = new JComboBox();
left.add(userList);
JPanel right = new JPanel();
right.setLayout(new BoxLayout(right, BoxLayout.PAGE_AXIS));
right.add(loginButton);
right.add(Box.createRigidArea(new Dimension(0, 5)));
right.add(quitButton);
right.add(Box.createHorizontalGlue());
right.add(Box.createRigidArea(new Dimension(0, 25)));
right.add(closeButton);
p.add(left);
p.add(Box.createRigidArea(new Dimension(10, 0)));
p.add(right);
getContentPane().add(h, BorderLayout.NORTH);
getContentPane().add(p);
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
client.quit();
connector.dispose();
dispose();
}
});
setLoggedOut();
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public class LoginAction extends AbstractAction {
private static final long serialVersionUID = 3596719854773863244L;
public void actionPerformed(ActionEvent e) {
ConnectDialog dialog = new ConnectDialog(SwingChatClient.this);
dialog.pack();
dialog.setVisible(true);
if (dialog.isCancelled()) {
return;
}
SocketAddress address = parseSocketAddress(dialog
.getServerAddress());
String name = dialog.getUsername();
handler = new SwingChatClientHandler(SwingChatClient.this);
client = new ChatClientSupport(name, handler);
nameField.setText(name);
serverField.setText(dialog.getServerAddress());
if (!client.connect(connector, address, dialog.isUseSsl())) {
JOptionPane.showMessageDialog(SwingChatClient.this,
"不能连接到当前地址: " + dialog.getServerAddress()
+ ". ");
}
}
}
private class LogoutAction extends AbstractAction {
private static final long serialVersionUID = 1655297424639924560L;
public void actionPerformed(ActionEvent e) {
try {
client.quit();
setLoggedOut();
} catch (Exception e1) {
JOptionPane.showMessageDialog(SwingChatClient.this,
"关闭连接失败.");
}
}
}
private class BroadcastAction extends AbstractAction {
/**
*
*/
private static final long serialVersionUID = -6276019615521905411L;
public void actionPerformed(ActionEvent e) {
client.broadcast(inputText.getText());
inputText.setText("");
}
}
private class QuitAction extends AbstractAction {
private static final long serialVersionUID = -6389802816912005370L;
public void actionPerformed(ActionEvent e) {
if (client != null) {
client.quit();
}
SwingChatClient.this.dispose();
}
}
private void setLoggedOut() {
inputText.setEnabled(false);
quitButton.setEnabled(false);
loginButton.setEnabled(true);
}
private void setLoggedIn() {
area.setText("");
inputText.setEnabled(true);
quitButton.setEnabled(true);
loginButton.setEnabled(false);
}
private void append(String text) {
area.insert(text, 0);
//area.append(text);
}
private void notifyError(String message) {
JOptionPane.showMessageDialog(this, message);
}
private SocketAddress parseSocketAddress(String s) {
s = s.trim();
int colonIndex = s.indexOf(":");
if (colonIndex > 0) {
String host = s.substring(0, colonIndex);
int port = parsePort(s.substring(colonIndex + 1));
return new InetSocketAddress(host, port);
} else {
int port = parsePort(s.substring(colonIndex + 1));
return new InetSocketAddress(port);
}
}
private int parsePort(String s) {
try {
return Integer.parseInt(s);
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException("非法的端口: " + s);
}
}
public void connected() {
//client.login();
}
public void disconnected() {
append("连接关闭.\n");
setLoggedOut();
}
public void error(String message) {
notifyError(message + "\n");
}
public void loggedIn() {
setLoggedIn();
append("你成功连接到服务器.\n");
}
public void loggedOut() {
append("你已经断开与服务器的连接.\n");
setLoggedOut();
}
public void messageReceived(String message) {
append(message + "\n");
}
public static void main(String[] args) {
SwingChatClient client = new SwingChatClient();
client.pack();
client.setVisible(true);
}
public void updateUserList(String user) {
if(user != null && !"".equals(user.trim())) {
String[] userArr = user.split("@");
userList.removeAllItems();
for(String s : userArr)
userList.addItem(s);
}
//throw new UnsupportedOperationException("Not supported yet.");
}
}
最麻烦的就是那个鬼协议了,要不停的扩充:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.gomt.slop.monitor;
import java.lang.reflect.Method;
/**
*
* @author pqs
*/
public class ChatProtocol {
private String message;
private String submessage;
private String cpcontent;
private String QN; //请求编号QN
private String PNUM;//总包号PNUM
private String PNO; //包号PNO
private String ST; //系统编号ST
private String CN; //命令编号
private String PW; //访问密码
private String MN; //设备唯一标示MN
private String Flag;//是否拆包及应答标志
private String STCODE;//站点编号
private String CP; //指令参数
private String CPSystemTime; //系统时间
private String CPQN; //请求编号
private String CPQnRtn; //请求回应代码
private String CPExeRtn; //执行结果回应代码
private String CPRtdInterval;//实时采样数据上报间隔
private String CPB01_Rtd;//污水实时采样数据
private String CP001_Rtd;//PH值实时采样数据
private String CP011_Rtd;//化学需氧量实时采样数据
private String CP060_Rtd;//氨氮实时采样数据
private String CP101_Rtd;//总磷实时采样数据
private String CP201_Rtd;//污水流量
private String CPB01_Min;//污水指定时间内最小值
private String CP001_Min;//PH值指定时间内最小值
private String CP011_Min;//化学需氧量指定时间内最小值
private String CP060_Min;//氨氮指定时间内最小值
private String CP101_Min;//总磷指定时间内最小值
private String CP201_Min;//污水流量指定时间内最小值
private String CPB01_Avg;//污水指定时间内平均值
private String CP001_Avg;//PH值指定时间内平均值
private String CP011_Avg;//化学需氧量指定时间内平均值
private String CP060_Avg;//氨氮指定时间内平均值
private String CP101_Avg;//总磷指定时间内平均值
private String CP201_Avg;//污水流量指定时间内平均值
private String CPB01_Max;//污水指定时间内最大值
private String CP001_Max;//PH值指定时间内最大值
private String CP011_Max;//化学需氧量指定时间内最大值
private String CP060_Max;//氨氮指定时间内最大值
private String CP101_Max;//总磷指定时间内最大值
private String CP201_Max;//污水流量指定时间内最大值
private String CPB01_ZsRtd;//污水实时采样折算数据
private String CP001_ZsRtd;//PH值实时采样折算数据
private String CP011_ZsRtd;//化学需氧量实时采样折算数据
private String CP060_ZsRtd;//氨氮实时采样折算数据
private String CP101_ZsRtd;//总磷实时采样折算数据
private String CP201_ZsRtd;//污水流量实时采样折算数据
private String CPB01_ZsMin;//污水指定时间内最小折算值
private String CP001_ZsMin;//PH值指定时间内最小折算值
private String CP011_ZsMin;//化学需氧量指定时间内最小折算值
private String CP060_ZsMin;//氨氮指定时间内最小折算值
private String CP101_ZsMin;//总磷指定时间内最小折算值
private String CP201_ZsMin;//污水流量指定时间内最小折算值
private String CPB01_ZsAvg;//污水指定时间内平均折算值
private String CP001_ZsAvg;//PH值指定时间内平均折算值
private String CP011_ZsAvg;//化学需氧量指定时间内平均折算值
private String CP060_ZsAvg;//氨氮指定时间内平均折算值
private String CP101_ZsAvg;//总磷指定时间内平均折算值
private String CP201_ZsAvg;//污水流量指定时间内平均折算值
private String CPB01_ZsMax;//污水指定时间内最大折算值
private String CP001_ZsMax;//PH值指定时间内最大折算值
private String CP011_ZsMax;//化学需氧量指定时间内最大折算值
private String CP060_ZsMax;//氨氮指定时间内最大折算值
private String CP101_ZsMax;//总磷指定时间内最大折算值
private String CP201_ZsMax;//污水流量指定时间内最大折算值
private String CPB01_Flag;//污水实时采样数据标记
private String CP001_Flag;//PH值实时采样数据标记
private String CP011_Flag;//化学需氧量实时采样数据标记
private String CP060_Flag;//氨氮实时采样数据标记
private String CP101_Flag;//总磷实时采样数据标记
private String CP201_Flag;//污水流量实时采样数据标记
private String CPB01_Cou;//污水指定时间内累计值
private String CP001_Cou;//PH值指定时间内累计值
private String CP011_Cou;//化学需氧量指定时间内累计值
private String CP060_Cou;//氨氮指定时间内累计值
private String CP101_Cou;//总磷指定时间内累计值
private String CP201_Cou;//污水流量指定时间内累计值
private String CPB01_RS;//污水设备运行状态的实时采样值
private String CP001_RS;//PH值设备运行状态的实时采样值
private String CP011_RS;//化学需氧量设备运行状态的实时采样值
private String CP060_RS;//氨氮设备运行状态的实时采样值
private String CP101_RS;//总磷设备运行状态的实时采样值
private String CP201_RS;//污水流量设备运行状态的实时采样值
private String CPB01_RT;//污水设备指定时间内的运行时间
private String CP001_RT;//PH值设备指定时间内的运行时间
private String CP011_RT;//化学需氧量设备指定时间内的运行时间
private String CP060_RT;//氨氮设备指定时间内的运行时间
private String CP101_RT;//总磷设备指定时间内的运行时间
private String CP201_RT;//污水流量设备指定时间内的运行时间
private String CPB01_Ala;//污水报警时间内采样值
private String CP001_Ala;//PH值报警时间内采样值
private String CP011_Ala;//化学需氧量报警时间内采样值
private String CP060_Ala;//氨氮报警时间内采样值
private String CP101_Ala;//总磷报警时间内采样值
private String CP201_Ala;//污水流量报警时间内采样值
private String CPB01_AlaAlarmType;//污水报警类型
private String CP001_AlaAlarmType;//PH值报警类型
private String CP011_AlaAlarmType;//化学需氧量报警类型
private String CP060_AlaAlarmType;//氨氮报警类型
private String CP101_AlaAlarmType;//总磷报警类型
private String CP201_AlaAlarmType;//污水流量报警类型
private String CPB01_UpValue;//污水报警上限值
private String CP001_UpValue;//PH值报警上限值
private String CP011_UpValue;//化学需氧量报警上限值
private String CP060_UpValue;//氨氮报警上限值
private String CP101_UpValue;//总磷报警上限值
private String CP201_UpValue;//污水流量报警上限值
private String CPB01_LowValue;//污水报警下限值
private String CP001_LowValue;//PH值报警下限值
private String CP011_LowValue;//化学需氧量报警下限值
private String CP060_LowValue;//氨氮报警下限值
private String CP101_LowValue;//总磷报警下限值
private String CP201_LowValue;//污水流量报警下限值
private String CPAlarmTime;//超标开始时间
private String CPAlarmType;//超标事件类型
private String CPReportTarget;//上位机地址标识
private String CPPolId;//污染物的编号
private String CPBeginTime;//开始时间
private String CPEndTime;//截止时间
private String CPDataTime;//数据时间信息
private String CPReportTime;//数据上报时间信息
private String CPFlag;//通讯标志
private String CPPNO;//包序号
private String CPPNUM;//总包号
private String CPPW;//访问密码
private String CPOverTime;//超时时间
private String CPRecount;//重发次数
private String CPWarnTime;//超限报警时间
private String CPCTime;//设备采样周期
private String CPMsg; //消息
private String CPONUsers;//在线用户
public String getCN() {
return CN;
}
public void setCN(String CN) {
this.CN = CN;
}
public String getCP() {
return CP;
}
public void setCP(String CP) {
this.CP = CP;
}
public String getCPB01_Rtd() {
return CPB01_Rtd;
}
public void setCPB01_Rtd(String CPB01_Rtd) {
this.CPB01_Rtd = CPB01_Rtd;
}
public String getCPExeRtn() {
return CPExeRtn;
}
public void setCPExeRtn(String CPExeRtn) {
this.CPExeRtn = CPExeRtn;
}
public String getCPQN() {
return CPQN;
}
public void setCPQN(String CPQN) {
this.CPQN = CPQN;
}
public String getCPQnRtn() {
return CPQnRtn;
}
public void setCPQnRtn(String CPQnRtn) {
this.CPQnRtn = CPQnRtn;
}
public String getCPRtdInterval() {
return CPRtdInterval;
}
public void setCPRtdInterval(String CPRtdInterval) {
this.CPRtdInterval = CPRtdInterval;
}
public String getCPSystemTime() {
return CPSystemTime;
}
public void setCPSystemTime(String CPSystemTime) {
this.CPSystemTime = CPSystemTime;
}
public String getFlag() {
return Flag;
}
public void setFlag(String Flag) {
this.Flag = Flag;
}
public String getMN() {
return MN;
}
public void setMN(String MN) {
this.MN = MN;
}
public String getPNO() {
return PNO;
}
public void setPNO(String PNO) {
this.PNO = PNO;
}
public String getPNUM() {
return PNUM;
}
public void setPNUM(String PNUM) {
this.PNUM = PNUM;
}
public String getPW() {
return PW;
}
public void setPW(String PW) {
this.PW = PW;
}
public String getQN() {
return QN;
}
public void setQN(String QN) {
this.QN = QN;
}
public String getST() {
return ST;
}
public void setST(String ST) {
this.ST = ST;
}
public String getSTCODE() {
return STCODE;
}
public void setSTCODE(String STCODE) {
this.STCODE = STCODE;
}
public String getCPAlarmTime() {
return CPAlarmTime;
}
public void setCPAlarmTime(String CPAlarmTime) {
this.CPAlarmTime = CPAlarmTime;
}
public String getCPAlarmType() {
return CPAlarmType;
}
public void setCPAlarmType(String CPAlarmType) {
this.CPAlarmType = CPAlarmType;
}
public String getCPBeginTime() {
return CPBeginTime;
}
public void setCPBeginTime(String CPBeginTime) {
this.CPBeginTime = CPBeginTime;
}
public String getCPCTime() {
return CPCTime;
}
public void setCPCTime(String CPCTime) {
this.CPCTime = CPCTime;
}
public String getCPDataTime() {
return CPDataTime;
}
public void setCPDataTime(String CPDataTime) {
this.CPDataTime = CPDataTime;
}
public String getCPEndTime() {
return CPEndTime;
}
public void setCPEndTime(String CPEndTime) {
this.CPEndTime = CPEndTime;
}
public String getCPFlag() {
return CPFlag;
}
public void setCPFlag(String CPFlag) {
this.CPFlag = CPFlag;
}
public String getCPOverTime() {
return CPOverTime;
}
public void setCPOverTime(String CPOverTime) {
this.CPOverTime = CPOverTime;
}
public String getCPPNO() {
return CPPNO;
}
public void setCPPNO(String CPPNO) {
this.CPPNO = CPPNO;
}
public String getCPPNUM() {
return CPPNUM;
}
public void setCPPNUM(String CPPNUM) {
this.CPPNUM = CPPNUM;
}
public String getCPPW() {
return CPPW;
}
public void setCPPW(String CPPW) {
this.CPPW = CPPW;
}
public String getCPPolId() {
return CPPolId;
}
public void setCPPolId(String CPPolId) {
this.CPPolId = CPPolId;
}
public String getCPRecount() {
return CPRecount;
}
public void setCPRecount(String CPRecount) {
this.CPRecount = CPRecount;
}
public String getCPReportTarget() {
return CPReportTarget;
}
public void setCPReportTarget(String CPReportTarget) {
this.CPReportTarget = CPReportTarget;
}
public String getCPReportTime() {
return CPReportTime;
}
public void setCPReportTime(String CPReportTime) {
this.CPReportTime = CPReportTime;
}
public String getCPWarnTime() {
return CPWarnTime;
}
public void setCPWarnTime(String CPWarnTime) {
this.CPWarnTime = CPWarnTime;
}
public String getCP001_Rtd() {
return CP001_Rtd;
}
public void setCP001_Rtd(String CP001_Rtd) {
this.CP001_Rtd = CP001_Rtd;
}
public String getCP011_Rtd() {
return CP011_Rtd;
}
public void setCP011_Rtd(String CP011_Rtd) {
this.CP011_Rtd = CP011_Rtd;
}
public String getCP060_Rtd() {
return CP060_Rtd;
}
public void setCP060_Rtd(String CP060_Rtd) {
this.CP060_Rtd = CP060_Rtd;
}
public String getCP101_Rtd() {
return CP101_Rtd;
}
public void setCP101_Rtd(String CP101_Rtd) {
this.CP101_Rtd = CP101_Rtd;
}
public String getCPMsg() {
return CPMsg;
}
public void setCPMsg(String CPMsg) {
this.CPMsg = CPMsg;
}
public String getCPONUsers() {
return CPONUsers;
}
public void setCPONUsers(String CPONUsers) {
this.CPONUsers = CPONUsers;
}
public String getCP201_Rtd() {
return CP201_Rtd;
}
public void setCP201_Rtd(String CP201_Rtd) {
this.CP201_Rtd = CP201_Rtd;
}
public String getCP001_Ala() {
return CP001_Ala;
}
public void setCP001_Ala(String CP001_Ala) {
this.CP001_Ala = CP001_Ala;
}
public String getCP001_Avg() {
return CP001_Avg;
}
public void setCP001_Avg(String CP001_Avg) {
this.CP001_Avg = CP001_Avg;
}
public String getCP001_Cou() {
return CP001_Cou;
}
public void setCP001_Cou(String CP001_Cou) {
this.CP001_Cou = CP001_Cou;
}
public String getCP001_Flag() {
return CP001_Flag;
}
public void setCP001_Flag(String CP001_Flag) {
this.CP001_Flag = CP001_Flag;
}
public String getCP001_LowValue() {
return CP001_LowValue;
}
public void setCP001_LowValue(String CP001_LowValue) {
this.CP001_LowValue = CP001_LowValue;
}
public String getCP001_Max() {
return CP001_Max;
}
public void setCP001_Max(String CP001_Max) {
this.CP001_Max = CP001_Max;
}
public String getCP001_Min() {
return CP001_Min;
}
public void setCP001_Min(String CP001_Min) {
this.CP001_Min = CP001_Min;
}
public String getCP001_RS() {
return CP001_RS;
}
public void setCP001_RS(String CP001_RS) {
this.CP001_RS = CP001_RS;
}
public String getCP001_RT() {
return CP001_RT;
}
public void setCP001_RT(String CP001_RT) {
this.CP001_RT = CP001_RT;
}
public String getCP001_UpValue() {
return CP001_UpValue;
}
public void setCP001_UpValue(String CP001_UpValue) {
this.CP001_UpValue = CP001_UpValue;
}
public String getCP001_ZsAvg() {
return CP001_ZsAvg;
}
public void setCP001_ZsAvg(String CP001_ZsAvg) {
this.CP001_ZsAvg = CP001_ZsAvg;
}
public String getCP001_ZsMax() {
return CP001_ZsMax;
}
public void setCP001_ZsMax(String CP001_ZsMax) {
this.CP001_ZsMax = CP001_ZsMax;
}
public String getCP001_ZsMin() {
return CP001_ZsMin;
}
public void setCP001_ZsMin(String CP001_ZsMin) {
this.CP001_ZsMin = CP001_ZsMin;
}
public String getCP001_ZsRtd() {
return CP001_ZsRtd;
}
public void setCP001_ZsRtd(String CP001_ZsRtd) {
this.CP001_ZsRtd = CP001_ZsRtd;
}
public String getCP011_Ala() {
return CP011_Ala;
}
public void setCP011_Ala(String CP011_Ala) {
this.CP011_Ala = CP011_Ala;
}
public String getCP011_Avg() {
return CP011_Avg;
}
public void setCP011_Avg(String CP011_Avg) {
this.CP011_Avg = CP011_Avg;
}
public String getCP011_Cou() {
return CP011_Cou;
}
public void setCP011_Cou(String CP011_Cou) {
this.CP011_Cou = CP011_Cou;
}
public String getCP011_Flag() {
return CP011_Flag;
}
public void setCP011_Flag(String CP011_Flag) {
this.CP011_Flag = CP011_Flag;
}
public String getCP011_LowValue() {
return CP011_LowValue;
}
public void setCP011_LowValue(String CP011_LowValue) {
this.CP011_LowValue = CP011_LowValue;
}
public String getCP011_Max() {
return CP011_Max;
}
public void setCP011_Max(String CP011_Max) {
this.CP011_Max = CP011_Max;
}
public String getCP011_Min() {
return CP011_Min;
}
public void setCP011_Min(String CP011_Min) {
this.CP011_Min = CP011_Min;
}
public String getCP011_RS() {
return CP011_RS;
}
public void setCP011_RS(String CP011_RS) {
this.CP011_RS = CP011_RS;
}
public String getCP011_RT() {
return CP011_RT;
}
public void setCP011_RT(String CP011_RT) {
this.CP011_RT = CP011_RT;
}
public String getCP011_UpValue() {
return CP011_UpValue;
}
public void setCP011_UpValue(String CP011_UpValue) {
this.CP011_UpValue = CP011_UpValue;
}
public String getCP011_ZsAvg() {
return CP011_ZsAvg;
}
public void setCP011_ZsAvg(String CP011_ZsAvg) {
this.CP011_ZsAvg = CP011_ZsAvg;
}
public String getCP011_ZsMax() {
return CP011_ZsMax;
}
public void setCP011_ZsMax(String CP011_ZsMax) {
this.CP011_ZsMax = CP011_ZsMax;
}
public String getCP011_ZsMin() {
return CP011_ZsMin;
}
public void setCP011_ZsMin(String CP011_ZsMin) {
this.CP011_ZsMin = CP011_ZsMin;
}
public String getCP011_ZsRtd() {
return CP011_ZsRtd;
}
public void setCP011_ZsRtd(String CP011_ZsRtd) {
this.CP011_ZsRtd = CP011_ZsRtd;
}
public String getCP060_Ala() {
return CP060_Ala;
}
public void setCP060_Ala(String CP060_Ala) {
this.CP060_Ala = CP060_Ala;
}
public String getCP060_Avg() {
return CP060_Avg;
}
public void setCP060_Avg(String CP060_Avg) {
this.CP060_Avg = CP060_Avg;
}
public String getCP060_Cou() {
return CP060_Cou;
}
public void setCP060_Cou(String CP060_Cou) {
this.CP060_Cou = CP060_Cou;
}
public String getCP060_Flag() {
return CP060_Flag;
}
public void setCP060_Flag(String CP060_Flag) {
this.CP060_Flag = CP060_Flag;
}
public String getCP060_LowValue() {
return CP060_LowValue;
}
public void setCP060_LowValue(String CP060_LowValue) {
this.CP060_LowValue = CP060_LowValue;
}
public String getCP060_Max() {
return CP060_Max;
}
public void setCP060_Max(String CP060_Max) {
this.CP060_Max = CP060_Max;
}
public String getCP060_Min() {
return CP060_Min;
}
public void setCP060_Min(String CP060_Min) {
this.CP060_Min = CP060_Min;
}
public String getCP060_RS() {
return CP060_RS;
}
public void setCP060_RS(String CP060_RS) {
this.CP060_RS = CP060_RS;
}
public String getCP060_RT() {
return CP060_RT;
}
public void setCP060_RT(String CP060_RT) {
this.CP060_RT = CP060_RT;
}
public String getCP060_UpValue() {
return CP060_UpValue;
}
public void setCP060_UpValue(String CP060_UpValue) {
this.CP060_UpValue = CP060_UpValue;
}
public String getCP060_ZsAvg() {
return CP060_ZsAvg;
}
public void setCP060_ZsAvg(String CP060_ZsAvg) {
this.CP060_ZsAvg = CP060_ZsAvg;
}
public String getCP060_ZsMax() {
return CP060_ZsMax;
}
public void setCP060_ZsMax(String CP060_ZsMax) {
this.CP060_ZsMax = CP060_ZsMax;
}
public String getCP060_ZsMin() {
return CP060_ZsMin;
}
public void setCP060_ZsMin(String CP060_ZsMin) {
this.CP060_ZsMin = CP060_ZsMin;
}
public String getCP060_ZsRtd() {
return CP060_ZsRtd;
}
public void setCP060_ZsRtd(String CP060_ZsRtd) {
this.CP060_ZsRtd = CP060_ZsRtd;
}
public String getCP101_Ala() {
return CP101_Ala;
}
public void setCP101_Ala(String CP101_Ala) {
this.CP101_Ala = CP101_Ala;
}
public String getCP101_Avg() {
return CP101_Avg;
}
public void setCP101_Avg(String CP101_Avg) {
this.CP101_Avg = CP101_Avg;
}
public String getCP101_Cou() {
return CP101_Cou;
}
public void setCP101_Cou(String CP101_Cou) {
this.CP101_Cou = CP101_Cou;
}
public String getCP101_Flag() {
return CP101_Flag;
}
public void setCP101_Flag(String CP101_Flag) {
this.CP101_Flag = CP101_Flag;
}
public String getCP101_LowValue() {
return CP101_LowValue;
}
public void setCP101_LowValue(String CP101_LowValue) {
this.CP101_LowValue = CP101_LowValue;
}
public String getCP101_Max() {
return CP101_Max;
}
public void setCP101_Max(String CP101_Max) {
this.CP101_Max = CP101_Max;
}
public String getCP101_Min() {
return CP101_Min;
}
public void setCP101_Min(String CP101_Min) {
this.CP101_Min = CP101_Min;
}
public String getCP101_RS() {
return CP101_RS;
}
public void setCP101_RS(String CP101_RS) {
this.CP101_RS = CP101_RS;
}
public String getCP101_RT() {
return CP101_RT;
}
public void setCP101_RT(String CP101_RT) {
this.CP101_RT = CP101_RT;
}
public String getCP101_UpValue() {
return CP101_UpValue;
}
public void setCP101_UpValue(String CP101_UpValue) {
this.CP101_UpValue = CP101_UpValue;
}
public String getCP101_ZsAvg() {
return CP101_ZsAvg;
}
public void setCP101_ZsAvg(String CP101_ZsAvg) {
this.CP101_ZsAvg = CP101_ZsAvg;
}
public String getCP101_ZsMax() {
return CP101_ZsMax;
}
public void setCP101_ZsMax(String CP101_ZsMax) {
this.CP101_ZsMax = CP101_ZsMax;
}
public String getCP101_ZsMin() {
return CP101_ZsMin;
}
public void setCP101_ZsMin(String CP101_ZsMin) {
this.CP101_ZsMin = CP101_ZsMin;
}
public String getCP101_ZsRtd() {
return CP101_ZsRtd;
}
public void setCP101_ZsRtd(String CP101_ZsRtd) {
this.CP101_ZsRtd = CP101_ZsRtd;
}
public String getCP201_Ala() {
return CP201_Ala;
}
public void setCP201_Ala(String CP201_Ala) {
this.CP201_Ala = CP201_Ala;
}
public String getCP201_Avg() {
return CP201_Avg;
}
public void setCP201_Avg(String CP201_Avg) {
this.CP201_Avg = CP201_Avg;
}
public String getCP201_Cou() {
return CP201_Cou;
}
public void setCP201_Cou(String CP201_Cou) {
this.CP201_Cou = CP201_Cou;
}
public String getCP201_Flag() {
return CP201_Flag;
}
public void setCP201_Flag(String CP201_Flag) {
this.CP201_Flag = CP201_Flag;
}
public String getCP201_LowValue() {
return CP201_LowValue;
}
public void setCP201_LowValue(String CP201_LowValue) {
this.CP201_LowValue = CP201_LowValue;
}
public String getCP201_Max() {
return CP201_Max;
}
public void setCP201_Max(String CP201_Max) {
this.CP201_Max = CP201_Max;
}
public String getCP201_Min() {
return CP201_Min;
}
public void setCP201_Min(String CP201_Min) {
this.CP201_Min = CP201_Min;
}
public String getCP201_RS() {
return CP201_RS;
}
public void setCP201_RS(String CP201_RS) {
this.CP201_RS = CP201_RS;
}
public String getCP201_RT() {
return CP201_RT;
}
public void setCP201_RT(String CP201_RT) {
this.CP201_RT = CP201_RT;
}
public String getCP201_UpValue() {
return CP201_UpValue;
}
public void setCP201_UpValue(String CP201_UpValue) {
this.CP201_UpValue = CP201_UpValue;
}
public String getCP201_ZsAvg() {
return CP201_ZsAvg;
}
public void setCP201_ZsAvg(String CP201_ZsAvg) {
this.CP201_ZsAvg = CP201_ZsAvg;
}
public String getCP201_ZsMax() {
return CP201_ZsMax;
}
public void setCP201_ZsMax(String CP201_ZsMax) {
this.CP201_ZsMax = CP201_ZsMax;
}
public String getCP201_ZsMin() {
return CP201_ZsMin;
}
public void setCP201_ZsMin(String CP201_ZsMin) {
this.CP201_ZsMin = CP201_ZsMin;
}
public String getCP201_ZsRtd() {
return CP201_ZsRtd;
}
public void setCP201_ZsRtd(String CP201_ZsRtd) {
this.CP201_ZsRtd = CP201_ZsRtd;
}
public String getCPB01_Ala() {
return CPB01_Ala;
}
public void setCPB01_Ala(String CPB01_Ala) {
this.CPB01_Ala = CPB01_Ala;
}
public String getCPB01_Avg() {
return CPB01_Avg;
}
public void setCPB01_Avg(String CPB01_Avg) {
this.CPB01_Avg = CPB01_Avg;
}
public String getCPB01_Cou() {
return CPB01_Cou;
}
public void setCPB01_Cou(String CPB01_Cou) {
this.CPB01_Cou = CPB01_Cou;
}
public String getCPB01_Flag() {
return CPB01_Flag;
}
public void setCPB01_Flag(String CPB01_Flag) {
this.CPB01_Flag = CPB01_Flag;
}
public String getCPB01_LowValue() {
return CPB01_LowValue;
}
public void setCPB01_LowValue(String CPB01_LowValue) {
this.CPB01_LowValue = CPB01_LowValue;
}
public String getCPB01_Max() {
return CPB01_Max;
}
public void setCPB01_Max(String CPB01_Max) {
this.CPB01_Max = CPB01_Max;
}
public String getCPB01_Min() {
return CPB01_Min;
}
public void setCPB01_Min(String CPB01_Min) {
this.CPB01_Min = CPB01_Min;
}
public String getCPB01_RS() {
return CPB01_RS;
}
public void setCPB01_RS(String CPB01_RS) {
this.CPB01_RS = CPB01_RS;
}
public String getCPB01_RT() {
return CPB01_RT;
}
public void setCPB01_RT(String CPB01_RT) {
this.CPB01_RT = CPB01_RT;
}
public String getCPB01_UpValue() {
return CPB01_UpValue;
}
public void setCPB01_UpValue(String CPB01_UpValue) {
this.CPB01_UpValue = CPB01_UpValue;
}
public String getCPB01_ZsAvg() {
return CPB01_ZsAvg;
}
public void setCPB01_ZsAvg(String CPB01_ZsAvg) {
this.CPB01_ZsAvg = CPB01_ZsAvg;
}
public String getCPB01_ZsMax() {
return CPB01_ZsMax;
}
public void setCPB01_ZsMax(String CPB01_ZsMax) {
this.CPB01_ZsMax = CPB01_ZsMax;
}
public String getCPB01_ZsMin() {
return CPB01_ZsMin;
}
public void setCPB01_ZsMin(String CPB01_ZsMin) {
this.CPB01_ZsMin = CPB01_ZsMin;
}
public String getCPB01_ZsRtd() {
return CPB01_ZsRtd;
}
public void setCPB01_ZsRtd(String CPB01_ZsRtd) {
this.CPB01_ZsRtd = CPB01_ZsRtd;
}
public String getCpcontent() {
return cpcontent;
}
public void setCpcontent(String cpcontent) {
this.cpcontent = cpcontent;
}
public String getCP001_AlaAlarmType() {
return CP001_AlaAlarmType;
}
public void setCP001_AlaAlarmType(String CP001_AlaAlarmType) {
this.CP001_AlaAlarmType = CP001_AlaAlarmType;
}
public String getCP011_AlaAlarmType() {
return CP011_AlaAlarmType;
}
public void setCP011_AlaAlarmType(String CP011_AlaAlarmType) {
this.CP011_AlaAlarmType = CP011_AlaAlarmType;
}
public String getCP060_AlaAlarmType() {
return CP060_AlaAlarmType;
}
public void setCP060_AlaAlarmType(String CP060_AlaAlarmType) {
this.CP060_AlaAlarmType = CP060_AlaAlarmType;
}
public String getCP101_AlaAlarmType() {
return CP101_AlaAlarmType;
}
public void setCP101_AlaAlarmType(String CP101_AlaAlarmType) {
this.CP101_AlaAlarmType = CP101_AlaAlarmType;
}
public String getCP201_AlaAlarmType() {
return CP201_AlaAlarmType;
}
public void setCP201_AlaAlarmType(String CP201_AlaAlarmType) {
this.CP201_AlaAlarmType = CP201_AlaAlarmType;
}
public String getCPB01_AlaAlarmType() {
return CPB01_AlaAlarmType;
}
public void setCPB01_AlaAlarmType(String CPB01_AlaAlarmType) {
this.CPB01_AlaAlarmType = CPB01_AlaAlarmType;
}
public void transferMessageToProtocol() {
if(submessage != null && !"".equals(submessage) && submessage.length() > 10) {
CP = cpcontent = submessage.substring(submessage.indexOf("CP=&&") + 5, submessage.length() -2);
final String dataSeg = submessage.substring(0, submessage.indexOf("CP=&&"));
String[] dataSegDataArr = dataSeg.split(";");
System.out.println("cpcontent = " + cpcontent);
//利用java的反射机制给属性赋值
Class myclass;
try {
myclass = Class.forName("com.gomt.slop.monitor.ChatProtocol");
//对数据段进行赋值
if(dataSegDataArr != null) {
for(String dataSegData : dataSegDataArr) {
try {
String[] dataSegDataNV = dataSegData.split("=");
System.out.println( dataSegDataNV[0] + " = " + dataSegDataNV[1]);
Method m = myclass.getMethod("set" + dataSegDataNV[0], String.class);
m.invoke(this, new Object[]{dataSegDataNV[1]});
}
catch(Exception ee) {
ee.printStackTrace();
}
}
}
if(CP != null && !"".equals(CP.trim()) && CP.length() > 5) {
String cpSegDataArr[] = CP.split(";");
if(cpSegDataArr != null && cpSegDataArr.length > 0) {
for(String cpSegData : cpSegDataArr) {
try {
if(cpSegData.indexOf("=") != cpSegData.lastIndexOf("=")) {
String[] commaCpSegData = cpSegData.split(",");
if(commaCpSegData.length > 1) {
int count = 0;
String firstName = "";
for(String s : commaCpSegData) {
if(count == 0) {
String[] cpSegDataNV = commaCpSegData[0].split("=");
firstName = cpSegDataNV[0].replace('-', '_');
Method m = myclass.getMethod("setCP" + cpSegDataNV[0].replace('-', '_'), String.class);
m.invoke(this, new Object[]{cpSegDataNV[1]});
}
else {
String[] cpSegDataNV = commaCpSegData[count].split("=");
Method m = myclass.getMethod("setCP" + firstName + cpSegDataNV[0].replace('-', '_'), String.class);
m.invoke(this, new Object[]{cpSegDataNV[1]});
}
count++;
}
}
}
else {
String[] cpSegDataNV = cpSegData.split("=");
System.err.println(cpSegDataNV[0] + " = " + cpSegDataNV[1]);
Method m = myclass.getMethod("setCP" + cpSegDataNV[0].replace('-', '_'), String.class);
m.invoke(this, new Object[]{cpSegDataNV[1]});
}
}
catch(Exception ee) {
ee.printStackTrace();
}
}
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
return;
}
public ChatProtocol(String message) {
this.message = message;
}
/**
* 判断消息是否合法
* @return
*/
public boolean isValidMessage() {
if(message == null || "".equals(message.trim()) || message.length() <= 10) {
return false;
}
if(!message.startsWith("##")) {
return false;
}
else {
return validateMessage();
}
}
/**
* 获取消息的长度信息
* @return
*/
public int getMesageLength() {
String lenStr = message.substring(2, 6);
int returnVal = 0;
try {
returnVal = Integer.parseInt(lenStr);
}
catch(java.lang.NumberFormatException nfe) {
}
return returnVal;
}
/**
* 获取CRC16验证信息
* @return
*/
public String getCRC() {
if(message == null || "".equals(message.trim())) {
return null;
}
return message.substring(message.length()-4);
}
/**
* 校验CRC的合法性
* @return
*/
public boolean validateMessage() {
try {
if(message.length() > 10) {
submessage = message.substring(6, message.length() -4);
System.out.println("submessage = " + submessage);
transferMessageToProtocol();
return true;
}
}
catch(Exception e) {
}
return false;//CRC16.getHex(submessage).equals(getCRC());
}
/**
* 返回实际的消息内容
* @return
*/
public String getSubMessage() {
return submessage;
}
/**
* 判断执行的操作是否为登陆动作
* @return
*/
public boolean isLogon() {
return message.indexOf("CN="+ ChatCommand.LOGIN + ";") > -1;
}
/**
* 判断执行的操作是否为退出操作
* @return
*/
public boolean isLogout() {
return message.indexOf("CN="+ ChatCommand.QUIT + ";") > -1;
}
//获取当前命令的请求类型, 需要用类的反射机制实现, 暂时用字符串截取
public int getProtocol() {
if(!"".equals(submessage)) {
final String protocol = submessage.substring(submessage.indexOf("CN=") + 3, submessage.indexOf("CN=") + 7);
System.out.println("protocol = " + protocol);
try {
return Integer.parseInt(protocol);
}
catch(java.lang.NumberFormatException nfe) {
}
}
return 0;
}
public String getCPcontent() {
if(null != cpcontent) return cpcontent;
else {
getProtocol();
return cpcontent;
}
}
public String getLogonUser() {
if(getProtocol() == ChatCommand.LOGIN) {
String stcode = submessage.substring(submessage.indexOf("STCODE=") + 7);
return stcode.substring(0, stcode.indexOf(";"));
}
return "";
}
public String getOldQN() {
int qnp = submessage.indexOf("QN=");
if(qnp > -1) {
return submessage.substring(qnp + 3, qnp+ 20);
}
return "";
}
public static void main(String[] args) {
ChatProtocol cp = new ChatProtocol("##0076QN=20080402010101222;ST=32;CN=6001;Flag=3;STCODE=station1;PW=123456;CP=&&&&0084");
System.out.println("消息是否合法:" + cp.isValidMessage());
System.out.println("getProtocol = " + cp.getProtocol());
System.out.println("getLogonUser = " + cp.getLogonUser());
System.out.println("oldQN = " + cp.getOldQN());
}
}
服务端:
public class SpringMain {
public static void main(String[] args) throws Exception {
if (System.getProperty("com.sun.management.jmxremote") != null) {
System.out.println("JMX enabled.");
} else {
System.out
.println("JMX disabled. Please set the "
+ "'com.sun.management.jmxremote' system property to enable JMX.");
}
getApplicationContext();
System.out.println("Listening ...");
}
public static ConfigurableApplicationContext getApplicationContext() {
return new ClassPathXmlApplicationContext("com/gomt/slop/monitor/serverContext.xml");
}
}
客户端一共有三种:swing(NIO非阻塞),applet(old IO,用以前的阻塞IO),还有一种就是C#的客户端(暂不提供代码)。
Applet客户端:
package com.gomt.slop.monitor.client;
import com.gomt.slop.monitor.CRC16;
import com.gomt.slop.monitor.ChatCommand;
import com.gomt.slop.monitor.ChatProtocol;
import com.gomt.slop.monitor.Util;
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class OtherChatClient extends Applet {
private static final long serialVersionUID = -1998630511274235821L;
protected boolean loggedIn = false;// 登入状态
protected Frame cp;// 聊天室框架
protected static int PORTNUM = 1234;//7777; // 缺省端口号7777
protected int port;// 实际端口号
protected Socket sock;
protected BufferedReader is;// 用于从sock读取数据的BufferedReader
protected PrintWriter pw;// 用于向sock写入数据的PrintWriter
protected TextField tf;// 用于输入的TextField
protected Choice userList; //用于显示在线的用户列表
protected TextArea ta;// 用于显示对话的TextArea
protected Button lib;// 登入按钮
protected Button lob;// 登出的按钮
final static String TITLE = "数据在线监测applet客户端";
protected String paintMessage;// 发表的消息
int i = 0;
final String name = "appletuser";
//public ChatParameter Chat;
enum CharParameter {
LOGIN,
BROADCAST,
QUIT
}
public void init() {
paintMessage = "正在生成聊天窗口";
repaint();
cp = new Frame(TITLE);
cp.setLayout(new BorderLayout());
String portNum = getParameter("port");
port = PORTNUM;
if (portNum != null) // 书上是portNum==null,十分有问题
port = Integer.parseInt(portNum);
// CGI
ta = new TextArea(14, 80);
ta.setEditable(false);// read only attribute
ta.setFont(new Font("Monospaced", Font.PLAIN, 11));
ta.setText("init()\r\n");
cp.add(BorderLayout.NORTH, ta);
Panel p = new Panel();
Button b;
// for login button
p.add(lib = new Button("登陆"));
lib.setEnabled(true);
lib.requestFocus();
lib.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
login();
lib.setEnabled(false);
lob.setEnabled(true);
tf.requestFocus();// 将键盘输入锁定再右边的文本框中
}
});
// for logout button
p.add(lob = new Button("退出"));
lob.setEnabled(false);
lob.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
logout();
lib.setEnabled(true);
lob.setEnabled(false);
lib.requestFocus();
}
});
userList = new Choice();
userList.add(" ");
userList.setSize(new Dimension(80, 10));
p.add(userList);
p.add(new Label("输入消息:"));
tf = new TextField(30);
tf.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (loggedIn) {
// int j = tf.getText().indexOf(":");
// if (j > 0)
// pw.println(CharParameter.BROADCAST + " " + tf.getText());
// else
// pw.println(CharParameter.BROADCAST + " " + tf.getText());
final String logonPacket = "QN="+Util.getQN()+ ";ST=32;CN=6003;Flag=3;PW=123456;CP=&&Msg=" + tf.getText() + "&&";
pw.println("##" + Util.formate4Bit(logonPacket.length()) + logonPacket + CRC16.getHex(logonPacket) + "");
tf.setText("");
}
}
});
p.add(tf);
cp.add(BorderLayout.SOUTH, p);
cp.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// 如果执行了setVisible或者dispose,关闭窗口
OtherChatClient.this.cp.setVisible(false);
OtherChatClient.this.cp.dispose();
logout();
}
});
cp.pack();
// 将Frame cp放在中间
Dimension us = cp.getSize(), them = Toolkit.getDefaultToolkit()
.getScreenSize();
int newX = (them.width - us.width) / 2;
int newY = (them.height - us.height) / 2;
cp.setLocation(newX, newY);
cp.setVisible(true);
paintMessage = "Window should now be visible";
repaint();
}
// 登录聊天室
public void login() {
if (loggedIn)
return;
try {
sock = new Socket(getCodeBase().getHost(), port);
is = new BufferedReader(
new InputStreamReader(sock.getInputStream()));
pw = new PrintWriter(sock.getOutputStream(), true);
} catch (IOException e) {
showStatus("Can't get socket: " + e);
cp.add(new Label("Can't get socket: " + e));
return;
}
// 假定登录(其实只是打印相关信息,并没有真正登录)
// pw.println(Chat.CMD_LOGIN+"AppletUser");
//pw.println(CharParameter.LOGIN + " " + "AppletUser");
final String logonPacket = "QN="+Util.getQN()+ ";ST=32;CN=6001;Flag=3;STCODE=" + name + ";PW=123456;CP=&&&&";
pw.println("##" + Util.formate4Bit(logonPacket.length()) + logonPacket + CRC16.getHex(logonPacket) + "");
loggedIn = true;
// 构造并且启动读入器,从服务器读取数据,输出到文本框中
// 这里使用一个线程来避免锁住资源(lockups)
new Thread(new Runnable() {
public void run() {
String line;
try {
while (loggedIn && ((line = is.readLine()) != null)) {
ta.append(line + "\n"); //.appendText(line + "\n");
String theMessage = (String) line;
ChatProtocol cp = new ChatProtocol(theMessage);
if(cp.isValidMessage()) {
System.out.println("合法的消息!");
int protocol = cp.getProtocol();
System.out.println("协议为:" + protocol + " QN = " + cp.getQN());
switch(protocol) {
case ChatCommand.USERLIST :
String users = cp.getCPONUsers();
if(users != null && !"".equals(users.trim())) {
String[] userArr = users.split("@");
userList.removeAll();
userList.add("全部");
for(String s : userArr) {
userList.add(s);
}
}
break;
}
}
}
} catch (IOException e) {
showStatus("我的天啊,掉线了也!!!!");
return;
}
}
}).start();
}
// 模仿退出的代码
public void logout() {
if (!loggedIn)
return;
loggedIn = false;
try {
if (sock != null) {
pw = new PrintWriter(sock.getOutputStream(), true);
//pw.println(CharParameter.QUIT + " " + "AppletUser");
final String logonPacket = "QN="+Util.getQN()+ ";ST=32;CN=6002;Flag=3;PW=123456;CP=&&&&";
pw.println("##" + Util.formate4Bit(logonPacket.length()) + logonPacket + CRC16.getHex(logonPacket) + "");
sock.close();
}
} catch (IOException ign) {
// 异常处理哦
}
}
// 没有设置stop的方法,即使从浏览器跳到另外一个网页的时候
// 聊天程序还可以继续运行
public void paint(Graphics g) {
Dimension d = getSize();
int h = d.height;
int w = d.width;
g.fillRect(0, 0, w, 2);
g.setColor(Color.black);
g.drawString(paintMessage, 10, (h / 2) - 5);
}
}
swing客户端:
package com.gomt.slop.monitor.client;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import com.gomt.slop.monitor.client.SwingChatClientHandler.Callback;
import javax.swing.JComboBox;
import javax.swing.JScrollPane;
import org.apache.mina.transport.socket.nio.NioSocketConnector;
/**
* Simple chat client based on Swing & MINA that implements the chat protocol.
*
* @author The Apache MINA Project (dev@mina.apache.org)
* @version $Rev$, $Date$
*/
public class SwingChatClient extends JFrame implements Callback {
private static final long serialVersionUID = 1538675161745436968L;
private JTextField inputText;
private JButton loginButton;
private JButton quitButton;
private JButton closeButton;
private JTextField serverField;
private JTextField nameField;
private JTextArea area;
private JComboBox userList;
private JScrollBar scroll;
private ChatClientSupport client;
private SwingChatClientHandler handler;
private NioSocketConnector connector;
public SwingChatClient() {
super("环境监测swing客户端");
connector = new NioSocketConnector();
loginButton = new JButton(new LoginAction());
loginButton.setText("连接");
quitButton = new JButton(new LogoutAction());
quitButton.setText("断开");
closeButton = new JButton(new QuitAction());
closeButton.setText("退出");
inputText = new JTextField(30);
inputText.setAction(new BroadcastAction());
area = new JTextArea(10, 50);
area.setLineWrap(true);
area.setEditable(false);
area.setAutoscrolls(true);
// scroll = new JScrollBar();
// scroll.add(area);
// scroll.setSize(new Dimension(200, 100));
JScrollPane scrollPane = new JScrollPane(area);
nameField = new JTextField(10);
nameField.setEditable(false);
serverField = new JTextField(10);
serverField.setEditable(false);
JPanel h = new JPanel();
h.setLayout(new BoxLayout(h, BoxLayout.LINE_AXIS));
h.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JLabel nameLabel = new JLabel("用户名: ");
JLabel serverLabel = new JLabel("服务器: ");
h.add(nameLabel);
h.add(Box.createRigidArea(new Dimension(10, 0)));
h.add(nameField);
h.add(Box.createRigidArea(new Dimension(10, 0)));
h.add(Box.createHorizontalGlue());
h.add(Box.createRigidArea(new Dimension(10, 0)));
h.add(serverLabel);
h.add(Box.createRigidArea(new Dimension(10, 0)));
h.add(serverField);
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.LINE_AXIS));
p.setBorder(new EmptyBorder(10, 10, 10, 10));
JPanel left = new JPanel();
left.setLayout(new BoxLayout(left, BoxLayout.PAGE_AXIS));
left.add(scrollPane);
//left.add(area);
left.add(Box.createRigidArea(new Dimension(0, 5)));
left.add(inputText);
left.add(Box.createHorizontalGlue());
left.add(Box.createRigidArea(new Dimension(0, 25)));
userList = new JComboBox();
left.add(userList);
JPanel right = new JPanel();
right.setLayout(new BoxLayout(right, BoxLayout.PAGE_AXIS));
right.add(loginButton);
right.add(Box.createRigidArea(new Dimension(0, 5)));
right.add(quitButton);
right.add(Box.createHorizontalGlue());
right.add(Box.createRigidArea(new Dimension(0, 25)));
right.add(closeButton);
p.add(left);
p.add(Box.createRigidArea(new Dimension(10, 0)));
p.add(right);
getContentPane().add(h, BorderLayout.NORTH);
getContentPane().add(p);
closeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
client.quit();
connector.dispose();
dispose();
}
});
setLoggedOut();
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public class LoginAction extends AbstractAction {
private static final long serialVersionUID = 3596719854773863244L;
public void actionPerformed(ActionEvent e) {
ConnectDialog dialog = new ConnectDialog(SwingChatClient.this);
dialog.pack();
dialog.setVisible(true);
if (dialog.isCancelled()) {
return;
}
SocketAddress address = parseSocketAddress(dialog
.getServerAddress());
String name = dialog.getUsername();
handler = new SwingChatClientHandler(SwingChatClient.this);
client = new ChatClientSupport(name, handler);
nameField.setText(name);
serverField.setText(dialog.getServerAddress());
if (!client.connect(connector, address, dialog.isUseSsl())) {
JOptionPane.showMessageDialog(SwingChatClient.this,
"不能连接到当前地址: " + dialog.getServerAddress()
+ ". ");
}
}
}
private class LogoutAction extends AbstractAction {
private static final long serialVersionUID = 1655297424639924560L;
public void actionPerformed(ActionEvent e) {
try {
client.quit();
setLoggedOut();
} catch (Exception e1) {
JOptionPane.showMessageDialog(SwingChatClient.this,
"关闭连接失败.");
}
}
}
private class BroadcastAction extends AbstractAction {
/**
*
*/
private static final long serialVersionUID = -6276019615521905411L;
public void actionPerformed(ActionEvent e) {
client.broadcast(inputText.getText());
inputText.setText("");
}
}
private class QuitAction extends AbstractAction {
private static final long serialVersionUID = -6389802816912005370L;
public void actionPerformed(ActionEvent e) {
if (client != null) {
client.quit();
}
SwingChatClient.this.dispose();
}
}
private void setLoggedOut() {
inputText.setEnabled(false);
quitButton.setEnabled(false);
loginButton.setEnabled(true);
}
private void setLoggedIn() {
area.setText("");
inputText.setEnabled(true);
quitButton.setEnabled(true);
loginButton.setEnabled(false);
}
private void append(String text) {
area.insert(text, 0);
//area.append(text);
}
private void notifyError(String message) {
JOptionPane.showMessageDialog(this, message);
}
private SocketAddress parseSocketAddress(String s) {
s = s.trim();
int colonIndex = s.indexOf(":");
if (colonIndex > 0) {
String host = s.substring(0, colonIndex);
int port = parsePort(s.substring(colonIndex + 1));
return new InetSocketAddress(host, port);
} else {
int port = parsePort(s.substring(colonIndex + 1));
return new InetSocketAddress(port);
}
}
private int parsePort(String s) {
try {
return Integer.parseInt(s);
} catch (NumberFormatException nfe) {
throw new IllegalArgumentException("非法的端口: " + s);
}
}
public void connected() {
//client.login();
}
public void disconnected() {
append("连接关闭.\n");
setLoggedOut();
}
public void error(String message) {
notifyError(message + "\n");
}
public void loggedIn() {
setLoggedIn();
append("你成功连接到服务器.\n");
}
public void loggedOut() {
append("你已经断开与服务器的连接.\n");
setLoggedOut();
}
public void messageReceived(String message) {
append(message + "\n");
}
public static void main(String[] args) {
SwingChatClient client = new SwingChatClient();
client.pack();
client.setVisible(true);
}
public void updateUserList(String user) {
if(user != null && !"".equals(user.trim())) {
String[] userArr = user.split("@");
userList.removeAllItems();
for(String s : userArr)
userList.addItem(s);
}
//throw new UnsupportedOperationException("Not supported yet.");
}
}
最麻烦的就是那个鬼协议了,要不停的扩充:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.gomt.slop.monitor;
import java.lang.reflect.Method;
/**
*
* @author pqs
*/
public class ChatProtocol {
private String message;
private String submessage;
private String cpcontent;
private String QN; //请求编号QN
private String PNUM;//总包号PNUM
private String PNO; //包号PNO
private String ST; //系统编号ST
private String CN; //命令编号
private String PW; //访问密码
private String MN; //设备唯一标示MN
private String Flag;//是否拆包及应答标志
private String STCODE;//站点编号
private String CP; //指令参数
private String CPSystemTime; //系统时间
private String CPQN; //请求编号
private String CPQnRtn; //请求回应代码
private String CPExeRtn; //执行结果回应代码
private String CPRtdInterval;//实时采样数据上报间隔
private String CPB01_Rtd;//污水实时采样数据
private String CP001_Rtd;//PH值实时采样数据
private String CP011_Rtd;//化学需氧量实时采样数据
private String CP060_Rtd;//氨氮实时采样数据
private String CP101_Rtd;//总磷实时采样数据
private String CP201_Rtd;//污水流量
private String CPB01_Min;//污水指定时间内最小值
private String CP001_Min;//PH值指定时间内最小值
private String CP011_Min;//化学需氧量指定时间内最小值
private String CP060_Min;//氨氮指定时间内最小值
private String CP101_Min;//总磷指定时间内最小值
private String CP201_Min;//污水流量指定时间内最小值
private String CPB01_Avg;//污水指定时间内平均值
private String CP001_Avg;//PH值指定时间内平均值
private String CP011_Avg;//化学需氧量指定时间内平均值
private String CP060_Avg;//氨氮指定时间内平均值
private String CP101_Avg;//总磷指定时间内平均值
private String CP201_Avg;//污水流量指定时间内平均值
private String CPB01_Max;//污水指定时间内最大值
private String CP001_Max;//PH值指定时间内最大值
private String CP011_Max;//化学需氧量指定时间内最大值
private String CP060_Max;//氨氮指定时间内最大值
private String CP101_Max;//总磷指定时间内最大值
private String CP201_Max;//污水流量指定时间内最大值
private String CPB01_ZsRtd;//污水实时采样折算数据
private String CP001_ZsRtd;//PH值实时采样折算数据
private String CP011_ZsRtd;//化学需氧量实时采样折算数据
private String CP060_ZsRtd;//氨氮实时采样折算数据
private String CP101_ZsRtd;//总磷实时采样折算数据
private String CP201_ZsRtd;//污水流量实时采样折算数据
private String CPB01_ZsMin;//污水指定时间内最小折算值
private String CP001_ZsMin;//PH值指定时间内最小折算值
private String CP011_ZsMin;//化学需氧量指定时间内最小折算值
private String CP060_ZsMin;//氨氮指定时间内最小折算值
private String CP101_ZsMin;//总磷指定时间内最小折算值
private String CP201_ZsMin;//污水流量指定时间内最小折算值
private String CPB01_ZsAvg;//污水指定时间内平均折算值
private String CP001_ZsAvg;//PH值指定时间内平均折算值
private String CP011_ZsAvg;//化学需氧量指定时间内平均折算值
private String CP060_ZsAvg;//氨氮指定时间内平均折算值
private String CP101_ZsAvg;//总磷指定时间内平均折算值
private String CP201_ZsAvg;//污水流量指定时间内平均折算值
private String CPB01_ZsMax;//污水指定时间内最大折算值
private String CP001_ZsMax;//PH值指定时间内最大折算值
private String CP011_ZsMax;//化学需氧量指定时间内最大折算值
private String CP060_ZsMax;//氨氮指定时间内最大折算值
private String CP101_ZsMax;//总磷指定时间内最大折算值
private String CP201_ZsMax;//污水流量指定时间内最大折算值
private String CPB01_Flag;//污水实时采样数据标记
private String CP001_Flag;//PH值实时采样数据标记
private String CP011_Flag;//化学需氧量实时采样数据标记
private String CP060_Flag;//氨氮实时采样数据标记
private String CP101_Flag;//总磷实时采样数据标记
private String CP201_Flag;//污水流量实时采样数据标记
private String CPB01_Cou;//污水指定时间内累计值
private String CP001_Cou;//PH值指定时间内累计值
private String CP011_Cou;//化学需氧量指定时间内累计值
private String CP060_Cou;//氨氮指定时间内累计值
private String CP101_Cou;//总磷指定时间内累计值
private String CP201_Cou;//污水流量指定时间内累计值
private String CPB01_RS;//污水设备运行状态的实时采样值
private String CP001_RS;//PH值设备运行状态的实时采样值
private String CP011_RS;//化学需氧量设备运行状态的实时采样值
private String CP060_RS;//氨氮设备运行状态的实时采样值
private String CP101_RS;//总磷设备运行状态的实时采样值
private String CP201_RS;//污水流量设备运行状态的实时采样值
private String CPB01_RT;//污水设备指定时间内的运行时间
private String CP001_RT;//PH值设备指定时间内的运行时间
private String CP011_RT;//化学需氧量设备指定时间内的运行时间
private String CP060_RT;//氨氮设备指定时间内的运行时间
private String CP101_RT;//总磷设备指定时间内的运行时间
private String CP201_RT;//污水流量设备指定时间内的运行时间
private String CPB01_Ala;//污水报警时间内采样值
private String CP001_Ala;//PH值报警时间内采样值
private String CP011_Ala;//化学需氧量报警时间内采样值
private String CP060_Ala;//氨氮报警时间内采样值
private String CP101_Ala;//总磷报警时间内采样值
private String CP201_Ala;//污水流量报警时间内采样值
private String CPB01_AlaAlarmType;//污水报警类型
private String CP001_AlaAlarmType;//PH值报警类型
private String CP011_AlaAlarmType;//化学需氧量报警类型
private String CP060_AlaAlarmType;//氨氮报警类型
private String CP101_AlaAlarmType;//总磷报警类型
private String CP201_AlaAlarmType;//污水流量报警类型
private String CPB01_UpValue;//污水报警上限值
private String CP001_UpValue;//PH值报警上限值
private String CP011_UpValue;//化学需氧量报警上限值
private String CP060_UpValue;//氨氮报警上限值
private String CP101_UpValue;//总磷报警上限值
private String CP201_UpValue;//污水流量报警上限值
private String CPB01_LowValue;//污水报警下限值
private String CP001_LowValue;//PH值报警下限值
private String CP011_LowValue;//化学需氧量报警下限值
private String CP060_LowValue;//氨氮报警下限值
private String CP101_LowValue;//总磷报警下限值
private String CP201_LowValue;//污水流量报警下限值
private String CPAlarmTime;//超标开始时间
private String CPAlarmType;//超标事件类型
private String CPReportTarget;//上位机地址标识
private String CPPolId;//污染物的编号
private String CPBeginTime;//开始时间
private String CPEndTime;//截止时间
private String CPDataTime;//数据时间信息
private String CPReportTime;//数据上报时间信息
private String CPFlag;//通讯标志
private String CPPNO;//包序号
private String CPPNUM;//总包号
private String CPPW;//访问密码
private String CPOverTime;//超时时间
private String CPRecount;//重发次数
private String CPWarnTime;//超限报警时间
private String CPCTime;//设备采样周期
private String CPMsg; //消息
private String CPONUsers;//在线用户
public String getCN() {
return CN;
}
public void setCN(String CN) {
this.CN = CN;
}
public String getCP() {
return CP;
}
public void setCP(String CP) {
this.CP = CP;
}
public String getCPB01_Rtd() {
return CPB01_Rtd;
}
public void setCPB01_Rtd(String CPB01_Rtd) {
this.CPB01_Rtd = CPB01_Rtd;
}
public String getCPExeRtn() {
return CPExeRtn;
}
public void setCPExeRtn(String CPExeRtn) {
this.CPExeRtn = CPExeRtn;
}
public String getCPQN() {
return CPQN;
}
public void setCPQN(String CPQN) {
this.CPQN = CPQN;
}
public String getCPQnRtn() {
return CPQnRtn;
}
public void setCPQnRtn(String CPQnRtn) {
this.CPQnRtn = CPQnRtn;
}
public String getCPRtdInterval() {
return CPRtdInterval;
}
public void setCPRtdInterval(String CPRtdInterval) {
this.CPRtdInterval = CPRtdInterval;
}
public String getCPSystemTime() {
return CPSystemTime;
}
public void setCPSystemTime(String CPSystemTime) {
this.CPSystemTime = CPSystemTime;
}
public String getFlag() {
return Flag;
}
public void setFlag(String Flag) {
this.Flag = Flag;
}
public String getMN() {
return MN;
}
public void setMN(String MN) {
this.MN = MN;
}
public String getPNO() {
return PNO;
}
public void setPNO(String PNO) {
this.PNO = PNO;
}
public String getPNUM() {
return PNUM;
}
public void setPNUM(String PNUM) {
this.PNUM = PNUM;
}
public String getPW() {
return PW;
}
public void setPW(String PW) {
this.PW = PW;
}
public String getQN() {
return QN;
}
public void setQN(String QN) {
this.QN = QN;
}
public String getST() {
return ST;
}
public void setST(String ST) {
this.ST = ST;
}
public String getSTCODE() {
return STCODE;
}
public void setSTCODE(String STCODE) {
this.STCODE = STCODE;
}
public String getCPAlarmTime() {
return CPAlarmTime;
}
public void setCPAlarmTime(String CPAlarmTime) {
this.CPAlarmTime = CPAlarmTime;
}
public String getCPAlarmType() {
return CPAlarmType;
}
public void setCPAlarmType(String CPAlarmType) {
this.CPAlarmType = CPAlarmType;
}
public String getCPBeginTime() {
return CPBeginTime;
}
public void setCPBeginTime(String CPBeginTime) {
this.CPBeginTime = CPBeginTime;
}
public String getCPCTime() {
return CPCTime;
}
public void setCPCTime(String CPCTime) {
this.CPCTime = CPCTime;
}
public String getCPDataTime() {
return CPDataTime;
}
public void setCPDataTime(String CPDataTime) {
this.CPDataTime = CPDataTime;
}
public String getCPEndTime() {
return CPEndTime;
}
public void setCPEndTime(String CPEndTime) {
this.CPEndTime = CPEndTime;
}
public String getCPFlag() {
return CPFlag;
}
public void setCPFlag(String CPFlag) {
this.CPFlag = CPFlag;
}
public String getCPOverTime() {
return CPOverTime;
}
public void setCPOverTime(String CPOverTime) {
this.CPOverTime = CPOverTime;
}
public String getCPPNO() {
return CPPNO;
}
public void setCPPNO(String CPPNO) {
this.CPPNO = CPPNO;
}
public String getCPPNUM() {
return CPPNUM;
}
public void setCPPNUM(String CPPNUM) {
this.CPPNUM = CPPNUM;
}
public String getCPPW() {
return CPPW;
}
public void setCPPW(String CPPW) {
this.CPPW = CPPW;
}
public String getCPPolId() {
return CPPolId;
}
public void setCPPolId(String CPPolId) {
this.CPPolId = CPPolId;
}
public String getCPRecount() {
return CPRecount;
}
public void setCPRecount(String CPRecount) {
this.CPRecount = CPRecount;
}
public String getCPReportTarget() {
return CPReportTarget;
}
public void setCPReportTarget(String CPReportTarget) {
this.CPReportTarget = CPReportTarget;
}
public String getCPReportTime() {
return CPReportTime;
}
public void setCPReportTime(String CPReportTime) {
this.CPReportTime = CPReportTime;
}
public String getCPWarnTime() {
return CPWarnTime;
}
public void setCPWarnTime(String CPWarnTime) {
this.CPWarnTime = CPWarnTime;
}
public String getCP001_Rtd() {
return CP001_Rtd;
}
public void setCP001_Rtd(String CP001_Rtd) {
this.CP001_Rtd = CP001_Rtd;
}
public String getCP011_Rtd() {
return CP011_Rtd;
}
public void setCP011_Rtd(String CP011_Rtd) {
this.CP011_Rtd = CP011_Rtd;
}
public String getCP060_Rtd() {
return CP060_Rtd;
}
public void setCP060_Rtd(String CP060_Rtd) {
this.CP060_Rtd = CP060_Rtd;
}
public String getCP101_Rtd() {
return CP101_Rtd;
}
public void setCP101_Rtd(String CP101_Rtd) {
this.CP101_Rtd = CP101_Rtd;
}
public String getCPMsg() {
return CPMsg;
}
public void setCPMsg(String CPMsg) {
this.CPMsg = CPMsg;
}
public String getCPONUsers() {
return CPONUsers;
}
public void setCPONUsers(String CPONUsers) {
this.CPONUsers = CPONUsers;
}
public String getCP201_Rtd() {
return CP201_Rtd;
}
public void setCP201_Rtd(String CP201_Rtd) {
this.CP201_Rtd = CP201_Rtd;
}
public String getCP001_Ala() {
return CP001_Ala;
}
public void setCP001_Ala(String CP001_Ala) {
this.CP001_Ala = CP001_Ala;
}
public String getCP001_Avg() {
return CP001_Avg;
}
public void setCP001_Avg(String CP001_Avg) {
this.CP001_Avg = CP001_Avg;
}
public String getCP001_Cou() {
return CP001_Cou;
}
public void setCP001_Cou(String CP001_Cou) {
this.CP001_Cou = CP001_Cou;
}
public String getCP001_Flag() {
return CP001_Flag;
}
public void setCP001_Flag(String CP001_Flag) {
this.CP001_Flag = CP001_Flag;
}
public String getCP001_LowValue() {
return CP001_LowValue;
}
public void setCP001_LowValue(String CP001_LowValue) {
this.CP001_LowValue = CP001_LowValue;
}
public String getCP001_Max() {
return CP001_Max;
}
public void setCP001_Max(String CP001_Max) {
this.CP001_Max = CP001_Max;
}
public String getCP001_Min() {
return CP001_Min;
}
public void setCP001_Min(String CP001_Min) {
this.CP001_Min = CP001_Min;
}
public String getCP001_RS() {
return CP001_RS;
}
public void setCP001_RS(String CP001_RS) {
this.CP001_RS = CP001_RS;
}
public String getCP001_RT() {
return CP001_RT;
}
public void setCP001_RT(String CP001_RT) {
this.CP001_RT = CP001_RT;
}
public String getCP001_UpValue() {
return CP001_UpValue;
}
public void setCP001_UpValue(String CP001_UpValue) {
this.CP001_UpValue = CP001_UpValue;
}
public String getCP001_ZsAvg() {
return CP001_ZsAvg;
}
public void setCP001_ZsAvg(String CP001_ZsAvg) {
this.CP001_ZsAvg = CP001_ZsAvg;
}
public String getCP001_ZsMax() {
return CP001_ZsMax;
}
public void setCP001_ZsMax(String CP001_ZsMax) {
this.CP001_ZsMax = CP001_ZsMax;
}
public String getCP001_ZsMin() {
return CP001_ZsMin;
}
public void setCP001_ZsMin(String CP001_ZsMin) {
this.CP001_ZsMin = CP001_ZsMin;
}
public String getCP001_ZsRtd() {
return CP001_ZsRtd;
}
public void setCP001_ZsRtd(String CP001_ZsRtd) {
this.CP001_ZsRtd = CP001_ZsRtd;
}
public String getCP011_Ala() {
return CP011_Ala;
}
public void setCP011_Ala(String CP011_Ala) {
this.CP011_Ala = CP011_Ala;
}
public String getCP011_Avg() {
return CP011_Avg;
}
public void setCP011_Avg(String CP011_Avg) {
this.CP011_Avg = CP011_Avg;
}
public String getCP011_Cou() {
return CP011_Cou;
}
public void setCP011_Cou(String CP011_Cou) {
this.CP011_Cou = CP011_Cou;
}
public String getCP011_Flag() {
return CP011_Flag;
}
public void setCP011_Flag(String CP011_Flag) {
this.CP011_Flag = CP011_Flag;
}
public String getCP011_LowValue() {
return CP011_LowValue;
}
public void setCP011_LowValue(String CP011_LowValue) {
this.CP011_LowValue = CP011_LowValue;
}
public String getCP011_Max() {
return CP011_Max;
}
public void setCP011_Max(String CP011_Max) {
this.CP011_Max = CP011_Max;
}
public String getCP011_Min() {
return CP011_Min;
}
public void setCP011_Min(String CP011_Min) {
this.CP011_Min = CP011_Min;
}
public String getCP011_RS() {
return CP011_RS;
}
public void setCP011_RS(String CP011_RS) {
this.CP011_RS = CP011_RS;
}
public String getCP011_RT() {
return CP011_RT;
}
public void setCP011_RT(String CP011_RT) {
this.CP011_RT = CP011_RT;
}
public String getCP011_UpValue() {
return CP011_UpValue;
}
public void setCP011_UpValue(String CP011_UpValue) {
this.CP011_UpValue = CP011_UpValue;
}
public String getCP011_ZsAvg() {
return CP011_ZsAvg;
}
public void setCP011_ZsAvg(String CP011_ZsAvg) {
this.CP011_ZsAvg = CP011_ZsAvg;
}
public String getCP011_ZsMax() {
return CP011_ZsMax;
}
public void setCP011_ZsMax(String CP011_ZsMax) {
this.CP011_ZsMax = CP011_ZsMax;
}
public String getCP011_ZsMin() {
return CP011_ZsMin;
}
public void setCP011_ZsMin(String CP011_ZsMin) {
this.CP011_ZsMin = CP011_ZsMin;
}
public String getCP011_ZsRtd() {
return CP011_ZsRtd;
}
public void setCP011_ZsRtd(String CP011_ZsRtd) {
this.CP011_ZsRtd = CP011_ZsRtd;
}
public String getCP060_Ala() {
return CP060_Ala;
}
public void setCP060_Ala(String CP060_Ala) {
this.CP060_Ala = CP060_Ala;
}
public String getCP060_Avg() {
return CP060_Avg;
}
public void setCP060_Avg(String CP060_Avg) {
this.CP060_Avg = CP060_Avg;
}
public String getCP060_Cou() {
return CP060_Cou;
}
public void setCP060_Cou(String CP060_Cou) {
this.CP060_Cou = CP060_Cou;
}
public String getCP060_Flag() {
return CP060_Flag;
}
public void setCP060_Flag(String CP060_Flag) {
this.CP060_Flag = CP060_Flag;
}
public String getCP060_LowValue() {
return CP060_LowValue;
}
public void setCP060_LowValue(String CP060_LowValue) {
this.CP060_LowValue = CP060_LowValue;
}
public String getCP060_Max() {
return CP060_Max;
}
public void setCP060_Max(String CP060_Max) {
this.CP060_Max = CP060_Max;
}
public String getCP060_Min() {
return CP060_Min;
}
public void setCP060_Min(String CP060_Min) {
this.CP060_Min = CP060_Min;
}
public String getCP060_RS() {
return CP060_RS;
}
public void setCP060_RS(String CP060_RS) {
this.CP060_RS = CP060_RS;
}
public String getCP060_RT() {
return CP060_RT;
}
public void setCP060_RT(String CP060_RT) {
this.CP060_RT = CP060_RT;
}
public String getCP060_UpValue() {
return CP060_UpValue;
}
public void setCP060_UpValue(String CP060_UpValue) {
this.CP060_UpValue = CP060_UpValue;
}
public String getCP060_ZsAvg() {
return CP060_ZsAvg;
}
public void setCP060_ZsAvg(String CP060_ZsAvg) {
this.CP060_ZsAvg = CP060_ZsAvg;
}
public String getCP060_ZsMax() {
return CP060_ZsMax;
}
public void setCP060_ZsMax(String CP060_ZsMax) {
this.CP060_ZsMax = CP060_ZsMax;
}
public String getCP060_ZsMin() {
return CP060_ZsMin;
}
public void setCP060_ZsMin(String CP060_ZsMin) {
this.CP060_ZsMin = CP060_ZsMin;
}
public String getCP060_ZsRtd() {
return CP060_ZsRtd;
}
public void setCP060_ZsRtd(String CP060_ZsRtd) {
this.CP060_ZsRtd = CP060_ZsRtd;
}
public String getCP101_Ala() {
return CP101_Ala;
}
public void setCP101_Ala(String CP101_Ala) {
this.CP101_Ala = CP101_Ala;
}
public String getCP101_Avg() {
return CP101_Avg;
}
public void setCP101_Avg(String CP101_Avg) {
this.CP101_Avg = CP101_Avg;
}
public String getCP101_Cou() {
return CP101_Cou;
}
public void setCP101_Cou(String CP101_Cou) {
this.CP101_Cou = CP101_Cou;
}
public String getCP101_Flag() {
return CP101_Flag;
}
public void setCP101_Flag(String CP101_Flag) {
this.CP101_Flag = CP101_Flag;
}
public String getCP101_LowValue() {
return CP101_LowValue;
}
public void setCP101_LowValue(String CP101_LowValue) {
this.CP101_LowValue = CP101_LowValue;
}
public String getCP101_Max() {
return CP101_Max;
}
public void setCP101_Max(String CP101_Max) {
this.CP101_Max = CP101_Max;
}
public String getCP101_Min() {
return CP101_Min;
}
public void setCP101_Min(String CP101_Min) {
this.CP101_Min = CP101_Min;
}
public String getCP101_RS() {
return CP101_RS;
}
public void setCP101_RS(String CP101_RS) {
this.CP101_RS = CP101_RS;
}
public String getCP101_RT() {
return CP101_RT;
}
public void setCP101_RT(String CP101_RT) {
this.CP101_RT = CP101_RT;
}
public String getCP101_UpValue() {
return CP101_UpValue;
}
public void setCP101_UpValue(String CP101_UpValue) {
this.CP101_UpValue = CP101_UpValue;
}
public String getCP101_ZsAvg() {
return CP101_ZsAvg;
}
public void setCP101_ZsAvg(String CP101_ZsAvg) {
this.CP101_ZsAvg = CP101_ZsAvg;
}
public String getCP101_ZsMax() {
return CP101_ZsMax;
}
public void setCP101_ZsMax(String CP101_ZsMax) {
this.CP101_ZsMax = CP101_ZsMax;
}
public String getCP101_ZsMin() {
return CP101_ZsMin;
}
public void setCP101_ZsMin(String CP101_ZsMin) {
this.CP101_ZsMin = CP101_ZsMin;
}
public String getCP101_ZsRtd() {
return CP101_ZsRtd;
}
public void setCP101_ZsRtd(String CP101_ZsRtd) {
this.CP101_ZsRtd = CP101_ZsRtd;
}
public String getCP201_Ala() {
return CP201_Ala;
}
public void setCP201_Ala(String CP201_Ala) {
this.CP201_Ala = CP201_Ala;
}
public String getCP201_Avg() {
return CP201_Avg;
}
public void setCP201_Avg(String CP201_Avg) {
this.CP201_Avg = CP201_Avg;
}
public String getCP201_Cou() {
return CP201_Cou;
}
public void setCP201_Cou(String CP201_Cou) {
this.CP201_Cou = CP201_Cou;
}
public String getCP201_Flag() {
return CP201_Flag;
}
public void setCP201_Flag(String CP201_Flag) {
this.CP201_Flag = CP201_Flag;
}
public String getCP201_LowValue() {
return CP201_LowValue;
}
public void setCP201_LowValue(String CP201_LowValue) {
this.CP201_LowValue = CP201_LowValue;
}
public String getCP201_Max() {
return CP201_Max;
}
public void setCP201_Max(String CP201_Max) {
this.CP201_Max = CP201_Max;
}
public String getCP201_Min() {
return CP201_Min;
}
public void setCP201_Min(String CP201_Min) {
this.CP201_Min = CP201_Min;
}
public String getCP201_RS() {
return CP201_RS;
}
public void setCP201_RS(String CP201_RS) {
this.CP201_RS = CP201_RS;
}
public String getCP201_RT() {
return CP201_RT;
}
public void setCP201_RT(String CP201_RT) {
this.CP201_RT = CP201_RT;
}
public String getCP201_UpValue() {
return CP201_UpValue;
}
public void setCP201_UpValue(String CP201_UpValue) {
this.CP201_UpValue = CP201_UpValue;
}
public String getCP201_ZsAvg() {
return CP201_ZsAvg;
}
public void setCP201_ZsAvg(String CP201_ZsAvg) {
this.CP201_ZsAvg = CP201_ZsAvg;
}
public String getCP201_ZsMax() {
return CP201_ZsMax;
}
public void setCP201_ZsMax(String CP201_ZsMax) {
this.CP201_ZsMax = CP201_ZsMax;
}
public String getCP201_ZsMin() {
return CP201_ZsMin;
}
public void setCP201_ZsMin(String CP201_ZsMin) {
this.CP201_ZsMin = CP201_ZsMin;
}
public String getCP201_ZsRtd() {
return CP201_ZsRtd;
}
public void setCP201_ZsRtd(String CP201_ZsRtd) {
this.CP201_ZsRtd = CP201_ZsRtd;
}
public String getCPB01_Ala() {
return CPB01_Ala;
}
public void setCPB01_Ala(String CPB01_Ala) {
this.CPB01_Ala = CPB01_Ala;
}
public String getCPB01_Avg() {
return CPB01_Avg;
}
public void setCPB01_Avg(String CPB01_Avg) {
this.CPB01_Avg = CPB01_Avg;
}
public String getCPB01_Cou() {
return CPB01_Cou;
}
public void setCPB01_Cou(String CPB01_Cou) {
this.CPB01_Cou = CPB01_Cou;
}
public String getCPB01_Flag() {
return CPB01_Flag;
}
public void setCPB01_Flag(String CPB01_Flag) {
this.CPB01_Flag = CPB01_Flag;
}
public String getCPB01_LowValue() {
return CPB01_LowValue;
}
public void setCPB01_LowValue(String CPB01_LowValue) {
this.CPB01_LowValue = CPB01_LowValue;
}
public String getCPB01_Max() {
return CPB01_Max;
}
public void setCPB01_Max(String CPB01_Max) {
this.CPB01_Max = CPB01_Max;
}
public String getCPB01_Min() {
return CPB01_Min;
}
public void setCPB01_Min(String CPB01_Min) {
this.CPB01_Min = CPB01_Min;
}
public String getCPB01_RS() {
return CPB01_RS;
}
public void setCPB01_RS(String CPB01_RS) {
this.CPB01_RS = CPB01_RS;
}
public String getCPB01_RT() {
return CPB01_RT;
}
public void setCPB01_RT(String CPB01_RT) {
this.CPB01_RT = CPB01_RT;
}
public String getCPB01_UpValue() {
return CPB01_UpValue;
}
public void setCPB01_UpValue(String CPB01_UpValue) {
this.CPB01_UpValue = CPB01_UpValue;
}
public String getCPB01_ZsAvg() {
return CPB01_ZsAvg;
}
public void setCPB01_ZsAvg(String CPB01_ZsAvg) {
this.CPB01_ZsAvg = CPB01_ZsAvg;
}
public String getCPB01_ZsMax() {
return CPB01_ZsMax;
}
public void setCPB01_ZsMax(String CPB01_ZsMax) {
this.CPB01_ZsMax = CPB01_ZsMax;
}
public String getCPB01_ZsMin() {
return CPB01_ZsMin;
}
public void setCPB01_ZsMin(String CPB01_ZsMin) {
this.CPB01_ZsMin = CPB01_ZsMin;
}
public String getCPB01_ZsRtd() {
return CPB01_ZsRtd;
}
public void setCPB01_ZsRtd(String CPB01_ZsRtd) {
this.CPB01_ZsRtd = CPB01_ZsRtd;
}
public String getCpcontent() {
return cpcontent;
}
public void setCpcontent(String cpcontent) {
this.cpcontent = cpcontent;
}
public String getCP001_AlaAlarmType() {
return CP001_AlaAlarmType;
}
public void setCP001_AlaAlarmType(String CP001_AlaAlarmType) {
this.CP001_AlaAlarmType = CP001_AlaAlarmType;
}
public String getCP011_AlaAlarmType() {
return CP011_AlaAlarmType;
}
public void setCP011_AlaAlarmType(String CP011_AlaAlarmType) {
this.CP011_AlaAlarmType = CP011_AlaAlarmType;
}
public String getCP060_AlaAlarmType() {
return CP060_AlaAlarmType;
}
public void setCP060_AlaAlarmType(String CP060_AlaAlarmType) {
this.CP060_AlaAlarmType = CP060_AlaAlarmType;
}
public String getCP101_AlaAlarmType() {
return CP101_AlaAlarmType;
}
public void setCP101_AlaAlarmType(String CP101_AlaAlarmType) {
this.CP101_AlaAlarmType = CP101_AlaAlarmType;
}
public String getCP201_AlaAlarmType() {
return CP201_AlaAlarmType;
}
public void setCP201_AlaAlarmType(String CP201_AlaAlarmType) {
this.CP201_AlaAlarmType = CP201_AlaAlarmType;
}
public String getCPB01_AlaAlarmType() {
return CPB01_AlaAlarmType;
}
public void setCPB01_AlaAlarmType(String CPB01_AlaAlarmType) {
this.CPB01_AlaAlarmType = CPB01_AlaAlarmType;
}
public void transferMessageToProtocol() {
if(submessage != null && !"".equals(submessage) && submessage.length() > 10) {
CP = cpcontent = submessage.substring(submessage.indexOf("CP=&&") + 5, submessage.length() -2);
final String dataSeg = submessage.substring(0, submessage.indexOf("CP=&&"));
String[] dataSegDataArr = dataSeg.split(";");
System.out.println("cpcontent = " + cpcontent);
//利用java的反射机制给属性赋值
Class myclass;
try {
myclass = Class.forName("com.gomt.slop.monitor.ChatProtocol");
//对数据段进行赋值
if(dataSegDataArr != null) {
for(String dataSegData : dataSegDataArr) {
try {
String[] dataSegDataNV = dataSegData.split("=");
System.out.println( dataSegDataNV[0] + " = " + dataSegDataNV[1]);
Method m = myclass.getMethod("set" + dataSegDataNV[0], String.class);
m.invoke(this, new Object[]{dataSegDataNV[1]});
}
catch(Exception ee) {
ee.printStackTrace();
}
}
}
if(CP != null && !"".equals(CP.trim()) && CP.length() > 5) {
String cpSegDataArr[] = CP.split(";");
if(cpSegDataArr != null && cpSegDataArr.length > 0) {
for(String cpSegData : cpSegDataArr) {
try {
if(cpSegData.indexOf("=") != cpSegData.lastIndexOf("=")) {
String[] commaCpSegData = cpSegData.split(",");
if(commaCpSegData.length > 1) {
int count = 0;
String firstName = "";
for(String s : commaCpSegData) {
if(count == 0) {
String[] cpSegDataNV = commaCpSegData[0].split("=");
firstName = cpSegDataNV[0].replace('-', '_');
Method m = myclass.getMethod("setCP" + cpSegDataNV[0].replace('-', '_'), String.class);
m.invoke(this, new Object[]{cpSegDataNV[1]});
}
else {
String[] cpSegDataNV = commaCpSegData[count].split("=");
Method m = myclass.getMethod("setCP" + firstName + cpSegDataNV[0].replace('-', '_'), String.class);
m.invoke(this, new Object[]{cpSegDataNV[1]});
}
count++;
}
}
}
else {
String[] cpSegDataNV = cpSegData.split("=");
System.err.println(cpSegDataNV[0] + " = " + cpSegDataNV[1]);
Method m = myclass.getMethod("setCP" + cpSegDataNV[0].replace('-', '_'), String.class);
m.invoke(this, new Object[]{cpSegDataNV[1]});
}
}
catch(Exception ee) {
ee.printStackTrace();
}
}
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
return;
}
public ChatProtocol(String message) {
this.message = message;
}
/**
* 判断消息是否合法
* @return
*/
public boolean isValidMessage() {
if(message == null || "".equals(message.trim()) || message.length() <= 10) {
return false;
}
if(!message.startsWith("##")) {
return false;
}
else {
return validateMessage();
}
}
/**
* 获取消息的长度信息
* @return
*/
public int getMesageLength() {
String lenStr = message.substring(2, 6);
int returnVal = 0;
try {
returnVal = Integer.parseInt(lenStr);
}
catch(java.lang.NumberFormatException nfe) {
}
return returnVal;
}
/**
* 获取CRC16验证信息
* @return
*/
public String getCRC() {
if(message == null || "".equals(message.trim())) {
return null;
}
return message.substring(message.length()-4);
}
/**
* 校验CRC的合法性
* @return
*/
public boolean validateMessage() {
try {
if(message.length() > 10) {
submessage = message.substring(6, message.length() -4);
System.out.println("submessage = " + submessage);
transferMessageToProtocol();
return true;
}
}
catch(Exception e) {
}
return false;//CRC16.getHex(submessage).equals(getCRC());
}
/**
* 返回实际的消息内容
* @return
*/
public String getSubMessage() {
return submessage;
}
/**
* 判断执行的操作是否为登陆动作
* @return
*/
public boolean isLogon() {
return message.indexOf("CN="+ ChatCommand.LOGIN + ";") > -1;
}
/**
* 判断执行的操作是否为退出操作
* @return
*/
public boolean isLogout() {
return message.indexOf("CN="+ ChatCommand.QUIT + ";") > -1;
}
//获取当前命令的请求类型, 需要用类的反射机制实现, 暂时用字符串截取
public int getProtocol() {
if(!"".equals(submessage)) {
final String protocol = submessage.substring(submessage.indexOf("CN=") + 3, submessage.indexOf("CN=") + 7);
System.out.println("protocol = " + protocol);
try {
return Integer.parseInt(protocol);
}
catch(java.lang.NumberFormatException nfe) {
}
}
return 0;
}
public String getCPcontent() {
if(null != cpcontent) return cpcontent;
else {
getProtocol();
return cpcontent;
}
}
public String getLogonUser() {
if(getProtocol() == ChatCommand.LOGIN) {
String stcode = submessage.substring(submessage.indexOf("STCODE=") + 7);
return stcode.substring(0, stcode.indexOf(";"));
}
return "";
}
public String getOldQN() {
int qnp = submessage.indexOf("QN=");
if(qnp > -1) {
return submessage.substring(qnp + 3, qnp+ 20);
}
return "";
}
public static void main(String[] args) {
ChatProtocol cp = new ChatProtocol("##0076QN=20080402010101222;ST=32;CN=6001;Flag=3;STCODE=station1;PW=123456;CP=&&&&0084");
System.out.println("消息是否合法:" + cp.isValidMessage());
System.out.println("getProtocol = " + cp.getProtocol());
System.out.println("getLogonUser = " + cp.getLogonUser());
System.out.println("oldQN = " + cp.getOldQN());
}
}
- slopMonitor.rar (586.3 KB)
- 下载次数: 256
相关推荐
在"SWT采用mina网络框架做聊天系统"这个主题中,我们将探讨如何结合这两者来构建一个实时通信平台。首先,我们需要理解SWT的基本概念,它是Eclipse项目的一部分,提供了与操作系统本地GUI控件交互的能力,使得Java...
这个“mina项目示例”很可能是通过MINA框架实现了一个客户端和服务端的通信示例。它可能包括以下部分: 1. **服务端启动**:创建MINA服务器端,监听指定端口,设置相应的处理器和过滤器链。 2. **客户端连接**:...
4. **学习优秀设计**:MINA是一个成熟的开源项目,它的设计模式和架构对于提升你的软件设计能力非常有帮助。 总的来说,Apache MINA是一个强大且灵活的网络框架,它的源码是一个宝贵的教育资源,对于任何想要深入...
Apache Mina是一个开源的网络通信应用框架,主要应用于Java平台,它为高性能、高可用性的网络应用程序提供了基础架构。在本文中,我们将深入探讨Mina的高级使用,特别是在文件图片传送、文件发送、XML和JSON报文处理...
Apache Mina是一个高性能、异步事件驱动的网络应用程序框架,用于快速开发可维护的高性能协议服务器和客户端。这个"apache-mina-2.0.4.rar"压缩包包含的是Apache Mina 2.0.4版本的源代码,是深入理解和定制Mina的...
Apache Mina是一个开源项目,它提供了一个高度可扩展和高性能的网络通信框架。这个实例是基于Mina框架构建的一个应用程序,名为"BTUSimulator",它可能是用来模拟某种网络通信或者服务的。让我们深入探讨一下Mina...
MINA (Java IO Network Application Framework) 是一个由Apache软件基金会开发的开源网络通信框架,主要应用于构建高性能、高可用性的网络服务器。这个压缩包包含了MINA API文档、自学手册以及开发指南,对于学习和...
项目名称为MinaTest,由java搭建而成的Mina基本框架的JavaProject项目,下载后直接用eclipse导入工程,如果报错,注意Jdk环境设置为1.6或以上,要配合使用mina的基本包和slf4j包等jar包,即可完美解决报错,非常基本...
总的来说,这个"mina.zip"是一个方便开发和测试Apache Mina应用的资源包,包含了运行Mina所需的所有依赖,简化了项目的构建和部署过程。通过理解和利用这些库,开发者可以高效地构建面向网络的服务,实现复杂的数据...
标签 "源码" 暗示MINA是一个开源项目,其源代码对公众开放,允许开发者研究、学习和定制。"工具"则表明MINA是一个用于开发的工具,可以帮助程序员简化网络编程的工作。 压缩包中的文件名揭示了一些关于MINA的特定...
MINA是Apache软件基金会的一个项目,它提供了一个高度可扩展和高性能的网络应用开发框架,适用于多种传输协议,如TCP/IP和UDP/IP,以及SSL/TLS加密。在大数据传输场景中,MINA因其非阻塞I/O模型而被广泛采用,能够...
Apache Mina是一个开源项目,它提供了一个高度可扩展的网络通信框架,用于简化开发高性能、高可用性的网络服务器和客户端应用程序。"Mina demo mina jar包"指的是使用Apache Mina框架创建的一个演示示例,这个示例...
Mina(全称“MINA: Minimalistic Application Networking API”)是Apache软件基金会的一个开源项目,它为开发者提供了一种简单而高效的方式来构建高性能、跨平台的网络应用。Mina的核心优势在于它的事件驱动和异步I...
MINA2(Java Multicast Network Application Architecture 2)是一个高性能、跨平台的网络应用程序框架,主要设计用于构建网络服务,尤其是TCP和UDP协议的应用。它提供了丰富的API和强大的功能,帮助开发者快速创建...
Apache MINA(Multipurpose Infrastructure for Network Applications)是一个高性能、异步事件驱动的网络应用程序框架,专为开发基于TCP/IP和UDP/IP协议的应用程序而设计。MINA的目标是简化网络编程,使得开发者...
`Android-MinaSocket` 是一个针对Android平台的长连接库,它基于Apache Mina框架,提供了稳定且高效的网络通信能力。 Apache Mina(Model-View-Controller for Network Applications)是一个高度可扩展和灵活的网络...
Apache Mina是一个开源的网络通信框架,常用于构建高性能、高效率的服务端应用程序,尤其在Java平台上。在本文中,我们将深入探讨Mina的核心概念,包括连接管理、心跳机制以及断线重连策略。 首先,让我们理解"Mina...