我想創建web應用程序發送短信通過gsm調制解調器在JSP中首先我把目的地手機號碼和短信文本在url中並通過request.getparameter和第一條消息得到沒有問題,但發送通過referenshing同一頁面再次發送郵件時,我得到這個異常:org.smslib端口在使用異常
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;
}
}
如果我在改變SerialModemGateway的定義靜態上課會解決問題嗎? – danarj
只是使其超出方法,使其靜態或不會相同,有一件事會在session過期時調用'gateway.stopGateway();或其他流關閉操作。 –