⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smgpsocketprocess.java

📁 中国电信小灵通短信平台SP端程序
💻 JAVA
字号:
package com.pansonlu.smgp;/** * <p>Title: SMGPSocketProcess</p> * <p>Description: 湖南电信短信网关通讯程序-->实现对短信网关的连接,短信的收发</p> * <p>用于建立与电信短信网关的Socket连接,同时收发登陆包,登陆响应包</p> * 该SOCKET连接用来收发数据(Submit,SubmitResp,Deliver,DeliverResp等) * <p>Copyright: Copyright (c) 2008</p> * <p>Company: sunrise Ltd.</p> * @author pansonlu * @version 1.0 */import java.io.*;import java.net.*;import java.util.Vector;import com.pansonlu.common.util.*;public class SMGPSocketProcess {  public Socket socket ;  public DataInputStream  inputStream;  public DataOutputStream outputStream;  public boolean isAvail  = false;  /** SMGPMOSocketProcess 的单例 **/  private static SMGPSocketProcess moSocketProcess = null;  /** 上行数据缓冲,当SMGPMOReceiveThread接受到上行数据后,将数据保存在该缓冲中,由   *  SMGPMODataSaveThread线程将数据再保存到数据库中 **/  public Vector vctMOData = new Vector(1,1);  public SMGPSocketProcess() {  }  /**取得SMGPMOSocketProcess的唯一实例 **/  public static SMGPSocketProcess getInstance(){    if(moSocketProcess == null){      moSocketProcess = new SMGPSocketProcess();    }    return moSocketProcess;  }  /**   * 与短信网关建立连接   * @throws java.lang.Exception   */  public void connectSMSG() throws Exception{    try{      Debug.outInfo("[SMGPMaster]"+PublicFunction.getFormatTime()+" "+SMGParameter.ServerIp +":"+ SMGParameter.ServerPort);      socket = new Socket(SMGParameter.ServerIp,SMGParameter.ServerPort);      //socket.setSoTimeout(SMGParameter.ActiveTestTime);  //设置超时      socket.setReceiveBufferSize(1*1024*1024); //设置缓冲      inputStream  = new DataInputStream(socket.getInputStream());      outputStream = new DataOutputStream(socket.getOutputStream());      loginSMSG();    }    catch(Exception ex){      throw ex;    }  }  /**   * 发送登陆包,接收响应包,登陆   * @throws java.lang.Exception   */  public void loginSMSG() throws Exception{    try{      SMGP loginMsg = new SMGP(SMGP.SMGP_LOGIN);      PublicFunction.send(outputStream,loginMsg.pack());      byte[] loginRespByte = PublicFunction.recv(inputStream);      SMGP loginRespMsg = new SMGP();      loginRespMsg.parsePack(loginRespByte);      if(loginRespMsg.Status == 0 ){        Debug.outInfo("[SMGPMaster]"+PublicFunction.getFormatTime()+" 连接ISMG成功");        this.isAvail = true;      }      else{        this.socket.close();        this.socket = null;        Debug.outInfo("[SMGPMaster]"+PublicFunction.getFormatTime()+" 连接ISMG失败,失败状态:"+loginRespMsg.Status);      }    }    catch(Exception ex){      throw ex;    }  }  /** 断开连接 **/  public void disclose(){    try{      if(this.inputStream !=null){        this.inputStream.close();        this.inputStream = null;      }      if(this.outputStream !=null){        this.outputStream.close();        this.outputStream = null;      }      if(this.socket !=null){        this.socket.close();        this.socket = null;      }    }    catch(Exception ex){      Debug.outError(ex);    }    this.isAvail = false;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -