📄 smppclient.java
字号:
package smppclient;
import java.io.*;
import java.util.Properties;
import com.logica.smpp.*;
import com.logica.smpp.pdu.*;
import com.logica.smpp.debug.Debug;
import com.logica.smpp.debug.Event;
import com.logica.smpp.debug.FileDebug;
import com.logica.smpp.debug.FileEvent;
import com.logica.smpp.util.Queue;
import javax.swing.JPanel;
import java.awt.Rectangle;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import java.awt.Font;
public class SMPPClient extends JPanel {
// *********************************************************************
/**
* Directory for creating of debug and event files.
*/
static final String dbgDir = "./";
/**
* The debug object.
*
* @see FileDebug
*/
static Debug debug = new FileDebug(dbgDir, "test.dbg");
/**
* The event object.
*
* @see FileEvent
*/
static Event event = new FileEvent(dbgDir, "test.evt");
/**
* File with default settings for the application.
*/
static String propsFilePath = "./smppclient.cfg";
static BufferedReader keyboard = new BufferedReader(new InputStreamReader(
System.in)); // @jve:decl-index=0:
/**
* This is the SMPP session used for communication with SMSC.
*/
static Session session = null;
/**
* Contains the parameters and default values for this test application such
* as system id, password, default npi and ton of sender etc.
*/
Properties properties = new Properties();
/**
* If the application is bound to the SMSC.
*/
boolean bound = false;
/**
* If the application has to keep reading commands from the keyboard and to
* do what's requested.
*/
private boolean keepRunning = true;
/**
* Address of the SMSC.
*/
String ipAddress = null;
/**
* The port number to bind to on the SMSC server.
*/
int port = 0;
/**
* The name which identifies you to SMSC.
*/
String systemId = null;
/**
* The password for authentication to SMSC.
*/
String password = null;
/**
* How you want to bind to the SMSC: transmitter (t), receiver (r) or
* transciever (tr). Transciever can both send messages and receive
* messages. Note, that if you bind as receiver you can still receive
* responses to you requests (submissions).
*/
String bindOption = "t";
/**
* Indicates that the Session has to be asynchronous. Asynchronous Session
* means that when submitting a Request to the SMSC the Session does not
* wait for a response. Instead the Session is provided with an instance of
* implementation of ServerPDUListener from the smpp library which receives
* all PDUs received from the SMSC. It's application responsibility to match
* the received Response with sended Requests.
*/
boolean asynchronous = false;
/**
* This is an instance of listener which obtains all PDUs received from the
* SMSC. Application doesn't have explicitly call Session's receive()
* function, all PDUs are passed to this application callback object. See
* documentation in Session, Receiver and ServerPDUEventListener classes
* form the SMPP library.
*/
SMPPTestPDUEventListener pduListener = null;
/**
* The range of addresses the smpp session will serve.
*/
AddressRange addressRange = new AddressRange();
/*
* for information about these variables have a look in SMPP 3.4
* specification
*/
String systemType = "";
String serviceType = "";
Address sourceAddress = new Address();
Address destAddress = new Address();
String scheduleDeliveryTime = "";
String validityPeriod = "";
String shortMessage = "";
int numberOfDestination = 1;
String messageId = "";
byte esmClass = 0;
byte protocolId = 0;
byte priorityFlag = 0;
byte registeredDelivery = 0;
byte replaceIfPresentFlag = 0;
byte dataCoding = 0;
byte smDefaultMsgId = 0;
/**
* If you attemt to receive message, how long will the application wait for
* data.
*/
long receiveTimeout = Data.RECEIVE_BLOCKING;
// *********************************************************************
private static final long serialVersionUID = 1L;
private JTextField smscIDAddTextField = null;
private JTextField systemIDTextField = null;
private JPasswordField systemPassTextField = null;
private JButton bindButton = null;
private JTextField smscPortTextField = null;
private JLabel systemNameLabel = null;
private JLabel smscIDAddLabel = null;
private JLabel smscPortLabel = null;
private JLabel systemPassLabel = null;
private JLabel bindOptionLabel = null;
private JLabel syncModeLabel = null;
private JLabel messageLabel = null;
private JTextField serviceTypeTextField = null;
private JLabel serviceTypeLabel = null;
private JTextField sourceTextField = null;
private JTextField destinationTextField = null;
private JLabel destinationAddressLabel = null;
private JButton submitButton = null;
private JTextField ripfTextField = null;
private JLabel ripfLabel = null;
private JTextField sdtTextField = null;
private JLabel sdtLabel = null;
private JTextField validityPeriodTextField = null;
private JLabel validityPeriodLabel = null;
private JLabel esmClassLabel = null;
private JTextField esmClassTextField = null;
private JTextField protocolIdTextField = null;
private JTextField priorityFlagTextField = null;
private JTextField regisDeliTextField = null;
private JTextField dataEncodingTextField = null;
private JTextField sdmiTextField = null;
private JLabel sdmiLabel = null;
private JLabel dataEncodingLabel = null;
private JLabel regidDeliLabel = null;
private JLabel priolityFlagLabel = null;
private JLabel protocolIdLabel = null;
private JButton unbindButton = null;
private JButton exitButton = null;
private JButton receiveButton = null;
private JTextField syncModeTextField = null;
private JTextField bindOptionTextField = null;
private JTextField timesSubmitTextField = null;
private JLabel timesSubmitLabel = null;
private JTextField sourceTonTextField = null;
private JTextField sourceNpiTextField = null;
private JLabel sourceTonLabel = null;
private JLabel sourceNpiLabel = null;
private JLabel destTonLabel = null;
private JLabel destNpiLabel = null;
private JTextField destTonTextField = null;
private JTextField destNpiTextField = null;
private JTextPane messageTextPane = null;
private JLabel statusLabel1 = null;
private JLabel statusLabel2 = null;
private JLabel statusLabel3 = null;
private JLabel titleLabel = null;
private JLabel sourceAddressLabel = null;
/**
* This is the default constructor
*/
public SMPPClient() {
super();
initialize();
initClient();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
sourceAddressLabel = new JLabel();
sourceAddressLabel.setBounds(new Rectangle(16, 279, 79, 21));
sourceAddressLabel.setText("Source Addr");
titleLabel = new JLabel();
titleLabel.setBounds(new Rectangle(14, 10, 210, 49));
titleLabel.setFont(new Font("Narkisim", Font.BOLD, 24));
titleLabel.setText("SMPP Client Demo");
statusLabel3 = new JLabel();
statusLabel3.setBounds(new Rectangle(15, 511, 466, 24));
statusLabel3.setText("");
statusLabel2 = new JLabel();
statusLabel2.setBounds(new Rectangle(15, 488, 466, 23));
statusLabel2.setText("");
statusLabel1 = new JLabel();
statusLabel1.setBounds(new Rectangle(15, 463, 466, 25));
statusLabel1.setText("");
destNpiLabel = new JLabel();
destNpiLabel.setBounds(new Rectangle(131, 372, 23, 20));
destNpiLabel.setText("NPI");
destTonLabel = new JLabel();
destTonLabel.setBounds(new Rectangle(15, 373, 27, 19));
destTonLabel.setText("TON");
sourceNpiLabel = new JLabel();
sourceNpiLabel.setBounds(new Rectangle(131, 305, 24, 20));
sourceNpiLabel.setText("NPI");
sourceTonLabel = new JLabel();
sourceTonLabel.setBounds(new Rectangle(15, 306, 26, 18));
sourceTonLabel.setText("TON");
timesSubmitLabel = new JLabel();
timesSubmitLabel.setBounds(new Rectangle(279, 406, 93, 23));
timesSubmitLabel.setText("Sub Times");
protocolIdLabel = new JLabel();
protocolIdLabel.setBounds(new Rectangle(279, 278, 94, 21));
protocolIdLabel.setText("Pro.ID");
priolityFlagLabel = new JLabel();
priolityFlagLabel.setBounds(new Rectangle(279, 303, 94, 22));
priolityFlagLabel.setText("Pri.Flag");
regidDeliLabel = new JLabel();
regidDeliLabel.setBounds(new Rectangle(279, 329, 94, 20));
regidDeliLabel.setText("Reg.Deli");
dataEncodingLabel = new JLabel();
dataEncodingLabel.setBounds(new Rectangle(279, 355, 93, 20));
dataEncodingLabel.setText("Data.Enc");
sdmiLabel = new JLabel();
sdmiLabel.setBounds(new Rectangle(279, 381, 94, 21));
sdmiLabel.setText("S.D.M.I");
esmClassLabel = new JLabel();
esmClassLabel.setBounds(new Rectangle(279, 252, 94, 21));
esmClassLabel.setText("Esm.Class");
validityPeriodLabel = new JLabel();
validityPeriodLabel.setBounds(new Rectangle(279, 226, 94, 22));
validityPeriodLabel.setText("Validity.P");
sdtLabel = new JLabel();
sdtLabel.setBounds(new Rectangle(279, 202, 94, 20));
sdtLabel.setText("S.D.Time");
ripfLabel = new JLabel();
ripfLabel.setBounds(new Rectangle(279, 176, 93, 21));
ripfLabel.setText("R.I.P.F");
destinationAddressLabel = new JLabel();
destinationAddressLabel.setBounds(new Rectangle(16, 347, 78, 21));
destinationAddressLabel.setText("Dest Addr");
serviceTypeLabel = new JLabel();
serviceTypeLabel.setBounds(new Rectangle(279, 150, 94, 21));
serviceTypeLabel.setText("Serv Type");
messageLabel = new JLabel();
messageLabel.setBounds(new Rectangle(15, 126, 75, 21));
messageLabel.setText("Message");
syncModeLabel = new JLabel();
syncModeLabel.setBounds(new Rectangle(278, 62, 60, 20));
syncModeLabel.setText("Sync Mod");
bindOptionLabel = new JLabel();
bindOptionLabel.setBounds(new Rectangle(348, 63, 59, 20));
bindOptionLabel.setText("Bind Opt");
systemPassLabel = new JLabel();
systemPassLabel.setBounds(new Rectangle(14, 85, 68, 22));
systemPassLabel.setText("Password");
smscPortLabel = new JLabel();
smscPortLabel.setBounds(new Rectangle(415, 15, 66, 20));
smscPortLabel.setText("SMSC Port");
smscIDAddLabel = new JLabel();
smscIDAddLabel.setBounds(new Rectangle(278, 15, 129, 20));
smscIDAddLabel.setText("SMSC ID Address");
systemNameLabel = new JLabel();
systemNameLabel.setBounds(new Rectangle(14, 62, 68, 21));
systemNameLabel.setText("System ID");
this.setSize(496, 587);
this.setLayout(null);
this.add(getSmscIDAddTextField(), null);
this.add(getSystemIDTextField(), null);
this.add(getSystemPassTextField(), null);
this.add(getBindButton(), null);
this.add(getSmscPortTextField(), null);
this.add(systemNameLabel, null);
this.add(smscIDAddLabel, null);
this.add(smscPortLabel, null);
this.add(systemPassLabel, null);
this.add(bindOptionLabel, null);
this.add(syncModeLabel, null);
this.add(messageLabel, null);
this.add(getServiceTypeTextField(), null);
this.add(serviceTypeLabel, null);
this.add(getSourceTextField(), null);
this.add(getDestinationTextField(), null);
this.add(destinationAddressLabel, null);
this.add(getSubmitButton(), null);
this.add(getRipfTextField(), null);
this.add(ripfLabel, null);
this.add(getSdtTextField(), null);
this.add(sdtLabel, null);
this.add(getValidityPeriodTextField(), null);
this.add(validityPeriodLabel, null);
this.add(esmClassLabel, null);
this.add(getEsmClassTextField(), null);
this.add(getProtocolIdTextField(), null);
this.add(getPriorityFlagTextField(), null);
this.add(getRegisDeliTextField(), null);
this.add(getDataEncodingTextField(), null);
this.add(getSdmiTextField(), null);
this.add(sdmiLabel, null);
this.add(dataEncodingLabel, null);
this.add(regidDeliLabel, null);
this.add(priolityFlagLabel, null);
this.add(protocolIdLabel, null);
this.add(getUnbindButton(), null);
this.add(getExitButton(), null);
this.add(getReceiveButton(), null);
this.add(getSyncModeTextField(), null);
this.add(getBindOptionTextField(), null);
this.add(getTimesSubmitTextField(), null);
this.add(timesSubmitLabel, null);
this.add(getSourceTonTextField(), null);
this.add(getSourceNpiTextField(), null);
this.add(sourceTonLabel, null);
this.add(sourceNpiLabel, null);
this.add(destTonLabel, null);
this.add(destNpiLabel, null);
this.add(getDestTonTextField(), null);
this.add(getDestNpiTextField(), null);
this.add(getMessageTextPane(), null);
this.add(statusLabel1, null);
this.add(statusLabel2, null);
this.add(statusLabel3, null);
this.add(titleLabel, null);
this.add(sourceAddressLabel, null);
}
/**
* This method initializes smscIDAddTextField
*
* @return javax.swing.JTextField
*/
private JTextField getSmscIDAddTextField() {
if (smscIDAddTextField == null) {
smscIDAddTextField = new JTextField();
smscIDAddTextField.setBounds(new Rectangle(278, 38, 130, 22));
smscIDAddTextField.setText("192.168.1.3");
}
return smscIDAddTextField;
}
/**
* This method initializes systemIDTextField
*
* @return javax.swing.JTextField
*/
private JTextField getSystemIDTextField() {
if (systemIDTextField == null) {
systemIDTextField = new JTextField();
systemIDTextField.setBounds(new Rectangle(85, 61, 140, 22));
systemIDTextField.setText("longminhhai");
}
return systemIDTextField;
}
/**
* This method initializes systemPassTextField
*
* @return javax.swing.JTextField
*/
private JPasswordField getSystemPassTextField() {
if (systemPassTextField == null) {
systemPassTextField = new JPasswordField();
systemPassTextField.setBounds(new Rectangle(85, 85, 140, 23));
systemPassTextField.setText("sf");
}
return systemPassTextField;
}
/**
* This method initializes bindButton
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -