org.smslib port in use exception

Posted by danar jabbar on Stack Overflow See other posts from Stack Overflow or by danar jabbar
Published on 2012-09-24T09:22:42Z Indexed on 2012/09/24 9:37 UTC
Read the original article Hit count: 515

Filed under:
|
|
|

I am trying to create web application to send sms by gsm modem in JSP first I put destination mobile number and sms text in url and get by request.getparameter and first message sent with no problem but when send a message again by referenshing the same page i get this exception:

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)

I tried to stop gateway and stop service but no hope My code:

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;
    }
    }

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp