📄 smreceiver.java
字号:
package com.tssx.ebiz.sgip;
import java.net.*;
import java.io.*;
import java.sql.*;
import java.util.*;
public class SMReceiver implements Runnable {
public java.net.Socket m_sk;
private static int spPort = 8808;
private static String loginName = "internet";
private static String loginPassword = "internet";
public static String driverName = "oracle.jdbc.driver.OracleDriver";
public static String url = "jdbc:oracle:thin:@192.168.8.227:1521:orcl";
public static String user="hnuninet";
public static String password="hnuninet";
public static int connectionWaitingTime = 60000;
/**
* SMReceiver 构造子注解。
*/
public SMReceiver(Socket socket) throws IOException {
this.m_sk=socket;
}
/**
* 启动应用程序。
* @param args 命令行自变量数组
*/
private static void init() throws FileNotFoundException,IOException{
File f=new File("smreceiver.properties");
InputStream is=new BufferedInputStream(new FileInputStream(f));
Properties sgipProps = new Properties();
sgipProps.load(is);
spPort = Integer.parseInt(sgipProps.getProperty("spPort"));
loginName = sgipProps.getProperty("loginName");
loginPassword = sgipProps.getProperty("loginPassword");
connectionWaitingTime = Integer.parseInt(sgipProps.getProperty("connectionWaitingTime"));
driverName = sgipProps.getProperty("driverName");
url = sgipProps.getProperty("url");
user = sgipProps.getProperty("user");
password = sgipProps.getProperty("password");
is.close();
}
public static void main(java.lang.String[] args) {
try{
init();
System.out.println("初始化数据");
ServerSocket serversocket =new ServerSocket(spPort);
while(true){
System.out.println("建立接受服务,等待数据");
Socket socket=serversocket.accept();
socket.setSoTimeout(connectionWaitingTime);
SMReceiver smreceiver =new SMReceiver(socket);
Thread thread=new Thread(smreceiver);
thread.start();
}
}
catch (FileNotFoundException e) {
System.out.println("没有找到属性文件");
}
catch (IOException e) {
System.out.println("建立接受服务或者读属性文件出错");
}catch(Exception e){
System.out.println(e);
}
//在此处插入用来启动应用程序的代码。
}
/**
* When an object implementing interface <code>Runnable</code> is used
* to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing
* thread.
* <p>
* The general contract of the method <code>run</code> is that it may
* take any action whatsoever.
*
* @see java.lang.Thread#run()
*/
public void run() {
try{
int bj=0;
DataOutputStream m_os = new DataOutputStream(m_sk.getOutputStream());
DataInputStream m_is = new DataInputStream(new BufferedInputStream(m_sk.getInputStream()));
while(true){
Integer4 commandLength = new Integer4();
Integer4 commandID = new Integer4();
m_is.mark(10);
commandLength.read(m_is);
commandID.read(m_is);
m_is.reset();
switch(commandID.intValue()){
case CommandID.SGIP_BIND_RESP:
this.bindresp(m_is,m_os);
break;
case CommandID.SGIP_SUBMIT_RESP:
this.submitresp(m_is,m_os);
break;
case CommandID.SGIP_UNBIND_RESP:
this.unbindresp(m_is,m_os);
break;
case CommandID.SGIP_DELIVER:
this.deliver(m_is,m_os);
break;
case CommandID.SGIP_REPORT:
this.submitreport(m_is,m_os);
break;
case CommandID.SGIP_BIND:
this.bind(m_is,m_os);
break;
case CommandID.SGIP_SUBMIT:
this.submit(m_is,m_os);
break;
case CommandID.SGIP_UNBIND:
this.unbind(m_is,m_os);
bj=1;
break;
case CommandID.SGIP_DELIVER_RESP:
this.deliverresp(m_is,m_os);
break;
case CommandID.SGIP_REPORT_RESP:
this.deliverreportresp(m_is,m_os);
break;
default:
byte aa=0;
aa=m_is.readByte();
break;
}
if(bj==1) break;
}
}catch(Exception e){
System.out.println("数据包传送完毕或者连接超时或者网络出现问题"+e);
}finally{
try {
m_sk.close();
} catch (Exception ee) {
System.out.println(ee);
}
}
}
public SMSBindResp bindresp(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException,Exception {
SMSBindResp smsbindresp=new SMSBindResp();
smsbindresp.read(m_is);
return smsbindresp;
}
public SMSSubmitResp submitresp(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException,Exception {
SMSSubmitResp smssubmitresp=new SMSSubmitResp();
smssubmitresp.read(m_is);
int messageLength=smssubmitresp.getMessageLength();
int commandID=smssubmitresp.getCommandID();
int result=smssubmitresp.getResult();
String reserve=smssubmitresp.getReserve();
return smssubmitresp;
}
public SMSUnBindResp unbindresp(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException,Exception {
SMSUnBindResp smsunbindresp=new SMSUnBindResp();
smsunbindresp.read(m_is);
return smsunbindresp;
}
public SMSDeliver deliver(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException,Exception {
SMSDeliver smsdeliver=new SMSDeliver();
smsdeliver.read(m_is);
SMSDeliverResp smsdeliverresp=new SMSDeliverResp();
smsdeliverresp.setSeqAddr(smsdeliver.seqAddr);
smsdeliverresp.setSeqDate(smsdeliver.seqDate);
smsdeliverresp.setSequence(smsdeliver.sequence);
smsdeliverresp.setResult(0);
smsdeliverresp.write(m_os);
System.out.println("定制、点播、取消");
SMSDeliverThread smsdeliverthread=new SMSDeliverThread(smsdeliver.seqAddr,smsdeliver.seqDate,smsdeliver.sequence,smsdeliver.messageLength,smsdeliver.commandID,
smsdeliver.getSpNumber(),smsdeliver.getUserNumber(),smsdeliver.getTp_pid(),smsdeliver.getTp_udhi(),smsdeliver.getMessageCoding(),
smsdeliver.getMsgLen(),smsdeliver.getMessageContent(),smsdeliver.getReserve());
Thread newThread = new Thread(smsdeliverthread);
newThread.start();
System.out.println(smsdeliver.getUserNumber()+" "+smsdeliver.getMessageContent());
return smsdeliver;
}
public SMSSubmitReport submitreport(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException,Exception {
SMSSubmitReport submitreport=new SMSSubmitReport();
submitreport.read(m_is);
SMSSubmitReportResp smssubmitreportresp=new SMSSubmitReportResp();
smssubmitreportresp.setSeqAddr(submitreport.seqAddr);
smssubmitreportresp.setSeqDate(submitreport.seqDate);
smssubmitreportresp.setSequence(submitreport.sequence);
smssubmitreportresp.setResult(0);
smssubmitreportresp.write(m_os);
System.out.println("状态报告");
SMSSubmitReportThread smssubmitreportthread=new SMSSubmitReportThread(submitreport.seqAddr,submitreport.seqDate,submitreport.sequence,submitreport.messageLength,submitreport.commandID,
submitreport.getSubmitSeqAddr(),submitreport.getSubmitSeqDate(),submitreport.getSubmitSequence(),submitreport.getReportType(),submitreport.getUserNumber(),submitreport.getState(),submitreport.getErrorCode(),submitreport.getReserve());
Thread newThread = new Thread(smssubmitreportthread);
newThread.start();
return submitreport;
}
public SMSBind bind(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException,Exception {
SMSBind smsbind=new SMSBind();
smsbind.read(m_is);
SMSBindResp smsbindresp=new SMSBindResp();
smsbindresp.setSeqAddr(smsbind.seqAddr);
smsbindresp.setSeqDate(smsbind.seqDate);
smsbindresp.setSequence(smsbind.sequence);
smsbindresp.setResult(0);
smsbindresp.write(m_os);
System.out.println("客户端连接");
return smsbind;
}
public SMSSubmit submit(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException,Exception {
SMSSubmit smssubmit=new SMSSubmit();
smssubmit.read(m_is);
SMSSubmitResp smssubmitresp=new SMSSubmitResp();
smssubmitresp.setSeqAddr(smssubmit.seqAddr);
smssubmitresp.setSeqDate(smssubmit.seqDate);
smssubmitresp.setSequence(smssubmit.sequence);
smssubmitresp.setResult(0);
smssubmitresp.write(m_os);
return smssubmit;
}
public SMSUnBind unbind(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException {
SMSUnBind smsunbind=new SMSUnBind();
smsunbind.read(m_is);
SMSUnBindResp smsunbindresp=new SMSUnBindResp();
smsunbindresp.setSeqAddr(smsunbind.seqAddr);
smsunbindresp.setSeqDate(smsunbind.seqDate);
smsunbindresp.setSequence(smsunbind.sequence);
smsunbindresp.write(m_os);
System.out.println("客户端退出");
return smsunbind;
}
public SMSDeliverResp deliverresp(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException,Exception {
SMSDeliverResp smsdeliverresp=new SMSDeliverResp();
smsdeliverresp.read(m_is);
int messageLength=smsdeliverresp.getMessageLength();
int commandID=smsdeliverresp.getCommandID();
int result=smsdeliverresp.getResult();
String reserve=smsdeliverresp.getReserve();
return smsdeliverresp;
}
public SMSDeliverReportResp deliverreportresp(DataInputStream m_is,DataOutputStream m_os) throws SgipException,IOException,Exception {
SMSDeliverReportResp smsdeliverreportresp=new SMSDeliverReportResp();
smsdeliverreportresp.read(m_is);
int messageLength=smsdeliverreportresp.getMessageLength();
int commandID=smsdeliverreportresp.getCommandID();
int result=smsdeliverreportresp.getResult();
String reserve=smsdeliverreportresp.getReserve();
return smsdeliverreportresp;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -