java comlib 短信猫发送短信报错 重复发送端口被占用 如何释放呢?高手请进来帮帮忙。
java comlib 短信猫发送短信报错 重复发送端口被占用 如何释放呢?高手请进来帮帮忙。
报错如下:
org.smslib.GatewayException: Comm library exception:
java.lang.RuntimeException: javax.comm.PortInUseException: Port currently owned by org.smslib
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:92)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:110)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:126)
at org.smslib.Service$1Starter.run(Service.java:222)
只能发一条,不能重复发送啊,重复发送就报端口被占用了。
package com.huanrong.util;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;
import javax.comm.CommPortIdentifier;
import javax.comm.SerialPort;
import
org.apache.log4j.Logger;
import org.smslib.AGateway;
import org.smslib.AGateway.Protocols;
import org.smslib.GatewayException;
import org.smslib.InboundMessage;
import org.smslib.Message.MessageEncodings;
import org.smslib.OutboundMessage;
import org.smslib.Service;
import org.smslib.modem.SerialModemGateway;
/**
*
* @ClassName: SendMsg
* @Description: 短信猫发送短信方法
* @author jay
* @date 2012-10-17 下午05:46:04
*
* 使用方法:
* SendMsg.sendMsg("电话号码","发送内容");
*
*/
public class SendMsg {
private static final Logger logger = Logger.getLogger(SendMsg.class);
private Service smsService;
/**
* 发送短信
*/
public SendMsg(String com) {
smsService = Service.getInstance();
String portName = com;//"/dev/ttyUSB0";// COM24
SerialModemGateway gateway = new SerialModemGateway(
"modem." + portName, portName, 9600, "wavecom", "PL2303");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setProtocol(Protocols.PDU);
gateway.setSimPin("0000");
try {
smsService.addGateway(gateway);
} catch (GatewayException ex) {
logger.error(ex.getMessage());
}
}
/**