採用MINA做的一個污水在線監測項目

花了幾天時間整了一下,暫時還沒有完工,不過先把源碼上傳一下,與大家分享一下。
服務端:
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 ([email protected])
* @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());
}
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章