2

I was just trying to send SMS using java as I require it in my Web App.But for testing purpose I am the code that is described in this site And the code is as follows

package logic;

import com.harshadura.gsm.smsdura.GsmModem;

/**
 * @author     : Harsha Siriwardena  <harshadura@gmail.com>
 * @copyrights : www.Durapix.org     <http://www.durapix.org>
 * @license    : GNU GPL v3          <http://www.gnu.org/licenses/>
 *
 * Example on how to simply send a SMS using the smsdura API Wrapper.
 */
public class TestSMS {

    private static String port = "COM3"; //Modem Port.
    private static int bitRate = 115200; //this is also optional. leave as it is.
    private static String modemName = "ZTE"; //this is optional.
    private static String modemPin = "0000"; //Pin code if any have assigned to the modem.
    private static String SMSC = "+9477000003"; //Message Center Number ex. Mobitel

    public static void main(String[] args) throws Exception {
        GsmModem gsmModem = new GsmModem();
        GsmModem.configModem(port, bitRate, modemName, modemPin, SMSC);
        gsmModem.Sender("+94712244555", "Test Message"); // (tp, msg)
    }
}

When I tried to run this,I am getting this error

-----------------------------
*** SMS-DURA - GSM MODEM SMS API WRAPPER ***
www.harshadura.com
-----------------------------
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.1
log4j:WARN No appenders could be found for logger (smslib).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException
    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)

Please anybody tell me how to fix this issue

SpringLearner
  • 13,738
  • 20
  • 78
  • 116

4 Answers4

2

basically you the program is unable to find the PORT,use

org.smslib.helper.CommPortIdentifier

to find the correct COM port from the list of ports.

maali
  • 134
  • 3
  • 14
1

I know this is not the sort of answer you expect on SO but given the alternative I think it's better than nothing.

a) Your library is reporting that your modem is not attached.
b) You don't know how to check if your modem is attached.

While not in any way related with the company I've used nexmo with great success in the past.

If it's a necessity of your app I would strongly suggest you approach the problem by the API route that will save you enormous amount of work.

There are several companies out there that provide this service and the usage is more or less straight-forward, you simply format a URL to pass parameters back to the company. Nexmo example:

// by calling a crafted url you are requesting the company to send the sms for you 
urlString = "https://rest.nexmo.com/sms/json?api_key={api_key}&api_secret={api_secret}&from=MyCompany20&to=447525856424&text=helloworld";
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
InputStream is = conn.getInputStream()

Nexmo is NOT the only one out there providing this service. They are the only one i've had hands on experience with.

Frankie
  • 24,627
  • 10
  • 79
  • 121
  • Thanks for the help so +1 but My prime aim is in the use in web application.Is it(the link you have provided) going to help in web apps – SpringLearner Oct 15 '13 at 06:47
  • Instead of USB modem can i use wifi hotspot for sending sms – SpringLearner Oct 15 '13 at 07:01
  • @javaBeginner I was recommending you offset sending the SMS's to an external provider. The only thing you would need would be for your webapp to have web access. – Frankie Oct 15 '13 at 07:03
  • @javaBeginner should be a matter of copy-paste. What issues are you having? – Frankie Oct 15 '13 at 15:10
  • same error that I have posted in the question,Can you please give me a full running code to test – SpringLearner Oct 16 '13 at 03:41
  • @javaBeginner start up from scratch a new program (without trying to load the `org.smslib.GatewayException` that is what's throwing the error. – Frankie Oct 16 '13 at 16:01
0

Copy the API(comm.jar),dll(win32com),properties file(javax.comm) in

1) If Net Beans tool you are using means

C:\Program Files\Java\jdk1.7.0\jre\lib\ext

and

C:\Program Files\Java\jdk1.7.0\jre\bin

2) If Eclipse tool you are using means

C:\Program Files\Java\jre7\lib\ext

and

C:\Program Files\Java\jre7\bin

as per the instructions given in Code projects.com where you downloaded this project.

Another way If you can configure your tool then do it, logic is the API's should be under your runtime JVM(jre). and make sure that the port which is given by you should be free that is no other apps should run on it.

Damodaran
  • 10,882
  • 10
  • 60
  • 81
0

Yes I also got this exception to in Harshadura's SMS wrapper.Their can be two things you did not do

  • You did not declare any appenders in the code so at the beginning of your code just type in this simple code to declare appenders.

    package logic;
    
    import com.harshadura.gsm.smsdura.GsmModem;
    
    /**
     * @author     : Harsha Siriwardena  <harshadura@gmail.com>
     * @copyrights : www.Durapix.org     <http://www.durapix.org>
     * @license    : GNU GPL v3          <http://www.gnu.org/licenses/>
     *
     * Example on how to simply send a SMS using the smsdura API Wrapper.
     */
    public class TestSMS {
    
    private static String port = "COM3"; //Modem Port.
    private static int bitRate = 115200; //this is also optional. leave as it is.
    private static String modemName = "ZTE"; //this is optional.
    private static String modemPin = "0000"; //Pin code if any have assigned to the modem.
    private static String SMSC = "+9477000003"; //Message Center Number ex. Mobitel
    
    public static void main(String[] args) throws Exception {
        BasicConfigurator.configure();//Declares appenders
        GsmModem gsmModem = new GsmModem();
        GsmModem.configModem(port, bitRate, modemName, modemPin, SMSC);
        gsmModem.Sender("+94712244555", "Test Message"); // (tp, msg)
    }    }
    
  • Identifying the port of your GSM modem. This you can solve by going to your My Computer Icon click manage > click device manager> click modems and Identify the port of your modem.

The port you identifed then write it on your code.String port="MyPort";

Heizy
  • 1
  • 4