我正在尝试创建 Web 应用程序以通过 JSP 中的 gsm 调制解调器发送短信首先我将目标手机号码和短信文本放入 url 并通过 request.getparameter 和第一条消息发送没有问题但是当通过引用同一页面再次发送消息时我得到这个例外:
org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: gnu.io.PortInUseException: org.smslib
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
at org.smslib.Service$1Starter.run(Service.java:276)
我试图停止网关并停止服务但没有希望我的代码:
public boolean sendMessage(String strMobileNo,String strSMSText)
{
try
{
OutboundMessage outboundMessage=new OutboundMessage();
SMS message=new SMS();
SerialModemGateway gateway = new SerialModemGateway("modem.com1", "COM12", 9600, "Huawie", "EF200");
gateway.setInbound(true);
gateway.setOutbound(true);
gateway.setSimPin("0000");
gateway.setSmscNumber("+9647701144010");
Service.getInstance().setOutboundMessageNotification(message);
Service.getInstance().addGateway(gateway);
Service.getInstance().startService();
outboundMessage.setText(strSMSText);
outboundMessage.setRecipient(strMobileNo);
outboundMessage.setEncoding(Message.MessageEncodings.ENCUCS2);
//outboundMessage.setDeliveryDelay(5000);
Service.getInstance().sendMessage(outboundMessage);
System.out.println(outboundMessage);
gateway.stopGateway();
Service.getInstance().stopService();
Thread.sleep(10000);
return true;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}