nguyenbahuong / smslib

Automatically exported from code.google.com/p/smslib
0 stars 0 forks source link

how to solve this exception : Port Currently owned by smslib #518

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Port is not getting released  .....

This software is distributed under the terms of the Apache v2.0 License.
Web Site: http://smslib.org
Version: 3.5.2
Gateway Added
Inside setServiousStatus ! Service Running
Inside setServiousStatus ! Service Running

Modem Information:
  Manufacturer: huawei
  Model: E1731
  Serial No: 354369045945434
  SIM IMSI: ** MASKED **
  Signal Level: -81 dBm
  Battery Level: 0%

===============================================================================
<< OutboundMessage >>
-------------------------------------------------------------------------------
 Gateway Id: *
 Message Id: 0
 Message UUID: ef9912b2-fe30-4865-8078-fe4ef937f534
 Encoding: 7-bit
 Date: Wed Oct 24 17:01:53 IST 2012
 SMSC Ref No: 
 Recipient: MyParents
 Dispatch Date: null
 Message Status: UNSENT
 Failure Cause: NO_ERROR
 Validity Period (Hours): -1
 Status Report: false
 Source / Destination Ports: -1 / -1
 Flash SMS: false
 Text: ASAs
 PDU data: C169700E
 Scheduled Delivery: null
===============================================================================

Example: Send message from a serial gsm modem.
SMSLib: A Java API library for sending and receiving SMS via a GSM modem or 
other supported gateways.
This software is distributed under the terms of the Apache v2.0 License.
Web Site: http://smslib.org
Version: 3.5.2
Inside setServiousStatus ! Service Running
Inside setServiousStatus ! Service Running
Inside setServiceStatus ! Service stopped
Service stopped
javax.faces.FacesException: #{noticeBean.send}: org.smslib.GatewayException: 
Comm library exception: java.lang.RuntimeException: 
javax.comm.PortInUseException: Port currently owned by org.smslib
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:90)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

Original issue reported on code.google.com by ntn.deve...@gmail.com on 24 Oct 2012 at 11:54

GoogleCodeExporter commented 9 years ago
i am receiving first message but when i try second time with same UI i am 
getting this exception... when i restart the server the messages get 
delivered...

Original comment by ntn.deve...@gmail.com on 24 Oct 2012 at 11:55

GoogleCodeExporter commented 9 years ago
Issue 514 has been merged into this issue.

Original comment by admin@smslib.org on 11 Nov 2012 at 5:19

GoogleCodeExporter commented 9 years ago
Issue 517 has been merged into this issue.

Original comment by admin@smslib.org on 11 Nov 2012 at 5:19

GoogleCodeExporter commented 9 years ago

Original comment by admin@smslib.org on 1 Jan 2014 at 9:25

GoogleCodeExporter commented 9 years ago

Original comment by admin@smslib.org on 5 Jan 2014 at 4:08

GoogleCodeExporter commented 9 years ago
close the gateway. u can use Service.getInstance().removeGateway(gateway);

public static void doIt(String number, String text) {
    try {
        OutboundMessage msg;
        OutboundNotification outboundNotification = new OutboundNotification();
        SerialModemGateway gateway = new SerialModemGateway(id, port, bitRate,     modemName, "E17u-1");
        gateway.setInbound(true);
        gateway.setOutbound(true);
        gateway.setSimPin(modemPin);
        Service.getInstance().setOutboundMessageNotification(outboundNotification);
        Service.getInstance().addGateway(gateway);
        Service.getInstance().startService();
        msg = new OutboundMessage(number, text);
        Service.getInstance().sendMessage(msg);
        System.out.println(msg);
        Service.getInstance().stopService();
        Service.getInstance().removeGateway(gateway);
    } catch (Exception ex) {
        if (ex.getStackTrace()[2].getLineNumber() == 189) {
            JOptionPane.showMessageDialog(null,
                    "Port currently owned by usb Modem's application. \n Please close it & run the programm again.",
                    "Port Exception",
                    JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
        } else {
            JOptionPane.showMessageDialog(null,
                    ex.getMessage(),
                    "Sending faile",
                    JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
        }
    }
}

public static class OutboundNotification implements 
IOutboundMessageNotification {
    public void process(AGateway gateway, OutboundMessage msg) {
        System.out.println("Outbound handler called from Gateway: " + gateway.getGatewayId());
        System.out.println(msg);
    }
}

public static void main(String[] args) throws Exception {

    modemName = "Huwawi";
    port = "COM7";
    bitRate = 115200;
    modemPin = "0000";
    SMSC = "+94785000005";
    String text="hai";

            String[] numbers = {"+94710433605","+94710433605"};
      for (String number : numbers) {

          SendSms app = new SendSms();
    app.doIt(number, text);
//Service.getInstance().stopService();
}

  }

Original comment by ishanbud...@gmail.com on 5 Apr 2015 at 11:16